Tag Archives: calculator

Training neural network using Nelder-Mead algorithm on TI Nspire

In this installment the Nelder-Mead method is used to train a simple neural network for the XOR problem. The network consisted of 2-input, 1-output, and 2 hidden layers, and is fully connected. In mainstream practical neural network, back propagation and other evolutionary algorithms are much more popular for training neural network for real world problem. Nelder-Mead is used here just out of curiosity to see how this general optimization routine performed under neural network settings on TI Nspire.
neural-network-xor1

The sigmoid function is declared in an TI Nspire function.
neural-network-xor2

For the XOR problem, the inputs are defined as two lists, and the expected output in another.
neural-network-xor3

The activation functions for each neuron are declared.
neural-network-xor4

To train the network, the sum of squared error function is used to feed into the Nelder-Mead algorithm for minimization. Random numbers are used for initial parameters.
neural-network-xor6
neural-network-xor7

Finally the resulting weights and bias are obtained from running the Nelder-Mead program.
neural-network-xor8

The comparison graph of the performance of the Nelder-Mead trained XOR neural network against expected values.
neural-network-xor9

 

Advertisements

P value of Shapiro-Wilk test on TI-84

In previous installment, the Shapiro-Wilk test is performed step by step on the TI-84.

To calculate the p-value from this W statistic obtained, the following steps can also be done on the TI-84 using some standard statistics function. Note that the approximation below are for the case 4 ≤ n ≤ 11.

The mean and standard deviation are derived using the below equations.
shapiro84-pvalue1

The W statistic is assigned from the correlation calculation results, and another variable V is calculated for the transformed W.
shapiro84-pvalue2

Finally, the standardized Z statistic and p-value is calculated using the mean, standard deviation, and the transformed W value.
shapiro84-pvalue3 shapiro84-pvalue4

Overclocking Casio fx-9860gII to the max with portable power bank

As discovered previously the overclocking program ftune performed better when USB cable is plugged in, it was not sure back then whether the data link or the extra power supply contributed to the performance boost. It is now confirmed power supply alone will do the trick.

The test is carried out using a Casio Basic program running a parameter searching for a logistic regression equation using the Nelder-Mead algorithm. A portable power bank is plugged to the USB port of the Casio fx-9860gII with ftune.

The tested portable USB power bank comes with 4000mAh capacity and 1A output, and is fully charged. There are 4 blue LED indicator lights.
casiousbpoweroverclock1

The power bank is turned on.
casiousbpoweroverclock2

The test result shown that the program run with power bank finished in 46 seconds, and the one without finished in 93 seconds.

Real estate refinancing – example from HP 12C to TI Nspire

From the “HP 12C Platinum Solutions Handbook”, an example is given on calculation of refinancing an existing mortgage (on page 7). Since the HP 12C is a special breed specializing in financial calculations, much of the steps are optimized and is different from using financial functions available on other higher end calculators like the TI Nspire. In the following re-work of the same example, the Finance Solver is called from within the Calculator Page and the Vars are recalled for calculations.

refinance0

Monthly payment on existing mortgage received by lender calculation.
refinance1

Monthly payment on new payment calculation.
refinance2

Net monthly payment to lender, and Present value of net monthly payment calculation.
refinance3

Bonferroni procedure

The Bonferroni procedure can be used in multiple comparison to determine which means differ. Using a sample set of data below with three groups of equal size data, the ANOVA 2-way function is calculated and the results stored in stat1. For convenience, the standard ANOVA is also calculated and the results stored in stat6.

bonferroni1

The original confidence level is set to 0.05. To obtain the corrected confidence level value, 0.05 is divided by the number of group of data, and then by 2 for 2-tail test. The new critical t-value is then determined. The means for each group is available in the stat6 variable set (by ANOVA), while the pooled standard deviation s can be obtained from stat1 variable set (by ANOVA 2-way).

bonferroni2

And then for each of the combination of group, calculate its new t-value, i.e. GA-GC, GB-GC, and GA-GB respectively.

bonferroni3

As shown above, the combination of GA-GB is less than the critical value of 2.7178, meaning that fail to reject H0 and therefore can conclude that μAB.

Working with Mahalanobis distance in TI Nspire CX

The Mahalanobis distance is an important method in statistical analysis. It is a different thinking from the common Euclidean distance and considered the dimensionality of standard deviation. In TI Nspire, there is no built-in function for Mahalanobis distance. However, it can be easily calculated using the matrix operations available.

mahalanobis1

Using independent variables x1, x2, and dependent variable y. Firstly, the covariance matrix is obtained by either the first inverse matrix equation above, or the next one where d is defined as row-wise as x1, x2, and a last row of 1’s.

mahalanobis2

Once the covariance matrix is determined, the Mahalanobis distance for x1, x2 can be determined by the above equation, which is a summation of distances times the number of observation minus one. The use of a sum function on matrix is just for convenience of input and display as the summation function can be very long.