Elman Network - Negative and above 1 calculation values - neural-network

I normliezed the data but still, get negative and above 1 values when calculate new data with encog Elman pattern.
Even when run the ElmanXOR sample as is:
layers: 1 input, 5 hidden, 1 output
activation: ActivationSigmoid
training: LevenbergMarquardtTraining:
a. Greedy
b. HybridStrategy -> NeuralSimulatedAnnealing
is it possible?

Neural Network Results:
input: 1 ,ideal=0 actual: 0.625124775182661
input: 0 ,ideal=1 actual: -0.476592365362806
input: 1 ,ideal=0 actual: -0.0206919867584277
input: 0 ,ideal=0 actual: 1.35539859989167
input: 0 ,ideal=0 actual: -0.387613018442168
input: 0 ,ideal=0 actual: -0.819489650390268
input: 0 ,ideal=1 actual: 1.2046874965753
input: 1 ,ideal=1 actual: 0.870695301738905
input: 1 ,ideal=1 actual: 0.159201074403962
input: 1 ,ideal=1 actual: 0.884482632556325

If you are using Encog's Sigmoid Activation function, you should only get output values between 0 and 1 as this is all the output function is capable of (are you sure your output node is not using a Linear activation function?). It should not be possible to get values above 1 or below -1.
(source: saedsayad.com)
I'm wondering if your data is not normalized correctly (can you upload a sample of your normalized data?).
When you normalized, I'm assuming you did something like this:
var analyst = new EncogAnalyst();
var wizard = new AnalystWizard(analyst);
wizard.Wizard(DataFile, true, AnalystFileFormat.DecpntComma);
This will normalize your data between -1 and 1. I think you should try adding this code to normalize everything to between 0 and 1.
foreach (AnalystField field in analyst.Script.Normalize.NormalizedFields)
{
field.NormalizedHigh = 1.0;
field.NormalizedLow = 0.0;
}
Alternatively, you could try a different activation function, like HyperbolicTangent, as this outputs between -1 and 1.

Related

Tableau mixing aggregate and non-aggregate results error

I have a problem creating a calculated field in Tableau. I have data like so:
ID ... Status Step1 Step2 Step3
1 ... Accepted 1 1 1
2 ... Waiting 1 0 0
3 ... Discard 0 0 0
4 ... Waiting 1 1 0
...
I would like to create a calculated column that will give me the name of the last Step, but only when status is 'Accepted'. Otherwise I want the status. The syntax is quite easy, it looks like this:
IF [Status] = 'Accepted' THEN (
IF [Step3] = 1 THEN 'Step3' ELSEIF [STEP2] = 1 THEN 'Step2' ELSEIF [STEP1] = '1' THEN 'Step1' ELSE 'Step0')
ELSE [Status]
The problem is that the column 'Status' is a Dimension and the 'Step' statuses come from Measure. So they are AGG(Step1), AGG(Step2),...
I guess that is the reason I get this error:
Cannot mix aggregate and non-aggregate comparisons or results in 'IF' expressions.
I am not very familiar with Tableau. Any idea how I can solve this?
Solution:
Just use function ATTR that will make the non-aggregate function (Status) into an aggregate one. Then it is possible to combine them and the calculation is working.
IF ATTR([Status]) = 'Accepted' THEN (
IF [Step3] = 1 THEN 'Step3' ELSEIF [STEP2] = 1 THEN 'Step2' ELSEIF [STEP1] = '1' THEN 'Step1' ELSE 'Step0')
ELSE ATTR([Status])
Tableau automatically interprets numeric values as measures. It appears though that in your case they are a boolean (0 for false, 1 for true) and really ought to be dimensions.
Convert Step 1, Step 2, and Step 3 to dimensions. Highlight the fields, right click, and choose Convert to Dimension.

Convolutiona code and viterbi decoding using matlab

i'm trying to encode and decode a simple message using Matlab. The message is denoted msg=[1 0 0 1 1 1 0 1]. the encoding step is fruitful but the decoding step " viterbi " return a binary string of zeros '0 0 0 0 0 0 0 0' not the initial msg. Hereafter the code source , i don't knwo where is the problem
trellis = poly2trellis(7,[171 133])
code = convenc(msg,trellis);
decoded = vitdec(code,trellis,64,'cont','hard');
thanks a lot.
You can try this line instead :
vitdec(code, trellis,8,'trunc','hard')
As in the MATLAB help says : "The 'cont' mode is appropriate when you invoke this function repeatedly and want to preserve continuity between successive invocations."
But your input vector is not like this.

Detect contiguous numbers - MATLAB

I coded a program that create some bunch of binary numbers like this:
out = [0,1,1,0,1,1,1,0,0,0,1,0];
I want check existence of nine 1 digit together in above out, for example when we have this in our output:
out_2 = [0,0,0,0,1,1,1,1,1,1,1,1,1];
or
out_3 = [0,0,0,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,0,0,0,1,1,0];
condition variable should be set to 1. We don't know exact position of start of ones in outvariable. It is random. I only want find existence of duplicate ones values in above variable (one occurrence or more).
PS.
We are searching for a general answer to find other duplicate numbers (not only 1 here and not only for binary data. this is just an example)
You can use convolution to solve such r-contiguous detection cases.
Case #1 : To find contiguous 1s in a binary array -
check = any(conv(double(input_arr),ones(r,1))>=r)
Sample run -
input_arr =
0 0 0 0 1 1 1 1 1 1 1 1 1
r =
9
check =
1
Case #2 : For detecting any number as contiguous, you could modify it a bit, like so -
check = any(conv(double(diff(input_arr)==0),ones(1,r-1))>=r-1)
Sample run -
input_arr =
3 5 2 4 4 4 5 5 2 2
r =
3
check =
1
To save Stackoverflow from further duplicates, also feel free to look into related problems -
Fast r-contiguous matching (based on location similarities).
r-contiguous matching, MATLAB.

Format of training data in CSV type for encog 3.0 and using it

I wonder that how can I make a csv file for storing training data in encog. Currently I have 200 features (f) as inputs and multi outputs (o) (for example author A, B ,C...). So how can organize the CSV file ? Should I look like this?
f1, f2, f3 ... f200, o1
f1, f2, f3 ... f200, o2
f1, f2, f3 ... f200, o3
Some of my questions are:
Can o1, o2 and o3 accept String ? (Authors' names).
Will the format of training csv file and testing cvs file look the same ?
Is it possible to feed the NN directly with the CSV file ? Or It must be converted to multi dimension array as this examples ? Since I have to 200 features as inputs, this will quite difficult.
double XOR_INPUT[][] = [
[0,0],
[1,0],
[0,1],
[1,1]
];
How to normalize the data in the csv file (to -+1 range) by using encog framework ?
Thank you very much.
No. A neural network operates only with float numbers, preferably 0 to 1 (output) or -1 to 1 (input). For strings, use 1 of n encoding.
So eg. if your outputs are 'a', 'b', 'c', set it to
1 0 0 = 'a'
0 1 0 = 'b'
0 0 1 = 'c'
You can also add a null class if necessary, for no result found.
You can read the data from csv, but encog is looking for everything in a 2d double array (or more correctly an 'array of arrays').
To simplify things, start with say 10 features.
Normalization is done per feature. So for each feature, the formula for normalization for a datapoint a is:
((a - min) / range) + 1
Where range = max - min of that feature.
So all input datapoints should be in the range -1 to 1.
Maybe post a real example of the data, that might give a better impression of what you need to do.

Finding correlation in an enum type data

I have the following dataset containing information about countries
5,1,648,16,10,2,0,3,5,1,1,0,1,1,1,0,0,0,0,0,1,0,0,1,0,0,
3,1,29,3,6,6,0,0,3,1,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,
4,1,2388,20,8,2,2,0,3,1,1,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,
...
The sixth column in each row indicates the main religion of the country: 0 is catholic, 1 is other christian, 2 is muslim, etc. Some of the other data is about if different colors are present in the flag of the country symbols they contain, and so on.
The description of the data can be found here. I have removed the string data columns though so it doesn't fit exactly like the information shown.
My problem is that I want to use co-variance matrices and Pearson correlation to see if, for example, the fact that a flag has the color red in it will tell anything about if the religion of that country has a bigger chance of being something than something else. But since the religion is enumerated, I am a bit lost on how to progress with this problem.
Your problem is that, despite the fact that your data is ordered, this order is arbitrary. The "distance" between "muslim" (enum val=1) to "hindu" (enum val=3) is not 2.
The most straight-forward way of tackling this issue is to convert enum values to binary indicator vectors:
Suppose you have
enum {
Catholic = 0
Protestant,
Muslim,
Jewish,
Hindu,
...
NumOfRel };
You replace the single entry of enum val with a binary vector of length NumOfRel with zeros everywhere except for a single 1 at the appropriate place:
For a Protestant entry, you'll have the following binary vector:
[ 0 1 0 0 ... ]
For a Jewish:
[ 0 0 0 1 0 ... ]
And so on...
This way, the "distance" between different religions is always 1.