Posts

Java: How to Make a Sudoku Game without Graphical User Interface (GUI)

Image
What's sudoku? Sudoku is a logic-based number-placement puzzle. The objective is to fill an n×n grid with n distinct digits from 1 to n, so that each column, each row, and each of the subgrids that compose the grid contains all of the digits from 1 to n without repetition. Usually, when we talk about sudoku, we refer to the common case n=9, which is an 9x9 sudoku. In fact, sudoku is closely related to mathematics, and there is a complicated mathematical principle behind it. Here I would like to share my Java assignment. The task is to create a simple sudoku game without a graphical user interface (GUI). In fact, Java is not my main language, so I'm not very proficient in it. I took Java as an elective course just because I was curious about Java programming. When I started learning Java, sometimes I got confused about the syntax of Java, because it is similar to both C++ and Python. To me, Java syntax seems like a combination of Python and C++. Sometimes, I get confused about w...

How to Predict Stock Prices with a Multilayer Perceptron (MLP) Neural Network

Image
Predicting stock prices is one of the simple applications of AI in finance. Here I'm using Keras, which is a high-level deep learning API in TensorFlow. I have attempted to predict the future stock price of Padini, a fashion company in Malaysia, and the following graph shows the results of my prediction: It's tiring to train an AI, since you need to test the model with different parameters and settings. I have spent a few hours to adjust the model and find its best settings. It really requires a good intuition. But when you done it, you will feel excited! Disclaimer: This AI model's prediction results are not completely accurate, please do not invest according to the prediction results, otherwise you would lose money and I will not be responsible. Here I will explain the mathematical algorithms behind the MLP Model and provide the Python code in Jupyter to train the AI. Model Updated: The number of neurons in the input layer is reduced to 150. Also, the number of hidden lay...

AI Explained: The Most Common Questions and Answers for Newbies

As a self-taught AI learner, I have been studying AI for a while and I would like to share my experience of learning AI to help others who are interested in learning AI. Here I have summarized some common questions to help answer those who are interested in AI and want to learn AI. Also, i f I think of more questions in the future, I will update this article. Q1: Is mathematics necessary for learning AI? Can I just skip mathematics and dive right in to learn AI? A1: It's not recommended that you skip mathematics when learning AI, otherwise you will have no idea what you’re doing. That is not a good way to learn AI. In fact, mathematics is the core of AI, and AI is actually a complex mathematical model. Almost all the AI courses will require you to learn mathematics first, especially vector calculus, linear algebra, and advanced statistics. As I said earlier, AI = Coding + Math, and they cannot be separated. The best way to learn AI is to know how it works. Q2: I have heard about ma...

The Role of Mathematics in Artificial Intelligence

Image
Many people think that AI is only about coding, but mathematics is actually a fundamental part of AI. AI = Math + Coding, and they are both essential. AI is impossible without math or coding. However, training AI does not necessarily require a lot of mathematical knowledge. Most people train AI without fully understanding the mathematical algorithms behind it. But it is better if you know how AI works with mathematical algorithms. In fact, AI is based on a mathematical model. Some mathematical functions and algorithms are used in the model. It sounds abstract, but you can basically imagine it as using calculus to optimize something. So, how do we train an AI? First, we use advanced mathematics to model an AI, then we use coding to train the AI because the process of training AI is tedious, so we let our computer handle all the training stuff. That is why learning mathematics can help you understand AI more deeply, not just coding. Linear algebra, vector calculus, and advanced statistic...

How to Create Your Own Python Module on Windows

Image
For instance, if you create a function called search_prime in a Python file named prime_number, you can import it using the following code: from prime_number import search_prime However, this method necessitates that the Python file be located in your workspace, otherwise, it will not function. An alternative approach is to install it into the Python library, which allows you to import it without needing the Python file in your workspace. Here are the steps to do so: 1. Utilize the setuptools module to include the details of the module you wish to install. Ensure your module is named setup.py and place it in your workspace. 2. Open the command prompt and navigate to your workspace directory. For instance, execute the command cd /users/user_name/OneDrive/Python Workspace, or you can directly open the command prompt in your workspace. 3. Execute the command setup.py sdist in the command prompt. This will generate some files in your workspace. 4. Navigate to the dist directory using the c...

Using Python to Find Prime Numbers

Image
What's a prime number? A prime number is a natural number that's only divisible by 1 and itself. Also, a composite number is a natural number with positive factors other than 1 and itself. Thus, we can conclude that a prime number is not a composite number by the definitions. There are many algorithms to find prime numbers. First, we will introduce the simplest way to find prime numbers. Determining whether a number is prime or not is not really very different from determining whether a number is composite or not. To determine whether a number is composite, it is by definition sufficient to find a factor other than 1 and itself. If we find such a factor m for a number n, i.e. m divides n, then we must have m < n. So we only need to find a factor of n in the range from 2 to n-1. Here is the code: However, this brute force algorithm will take a lot of time to find the prime numbers if the range is too large. There is a better algorithm to save the time. In ancient Greece, a ma...

Train a Simple AI Using Jupyter Notebook

Image
The algorithms used to train the AI are backpropagation and gradient descent. Here is my code, for reference only: %load_ext jupyter_black %matplotlib inline import numpy as np import matplotlib.colors as mcolors import matplotlib.pyplot as plt def plot_training(x, y, iterations=10000, aggression=3.5, noise=1): global W1, W2, W3, b1, b2, b3 fig, ax = plt.subplots(figsize=(8, 8), dpi=80) ax.set_xlim([0, 1]) ax.set_ylim([0, 1]) ax.set_aspect(1) xx = np.arange(0, 1.01, 0.01) yy = np.arange(0, 1.01, 0.01) X, Y = np.meshgrid(xx, yy) Z = ((X - 0.5) ** 2 + (Y - 1) ** 2) ** (1 / 2) / (1.25) ** (1 / 2) im = ax.imshow(Z, vmin=0, vmax=1, extent=[0, 1, 1, 0], cmap=blueMap) ax.plot(y[0], y[1], lw=1.5, color=green) while iterations >= 0: j_W1 = J_W1(x, y) * (1 + np.random.randn() * noise) j_W2 = J_W2(x, y) * (1 + np.random.randn() * noise) j_W3 = J_W3(x, y) * (1 + np.random.randn() * noise) j_b1 = J_b1(x, y) * (1 + np...