Apply a train-completed model to a new project Encog - artificial-intelligence

I trained my AI and get the final model in Encog. and I know that by using NorminalizationHelper , i could get the normalization data.
like in the example from "Encog quick start" below :
[ NormalizationHelper :
[ ColumnDefinition : mpg( continuous ) ; low =9.000000 , high =46.600000 ,mean
=23.514573 , sd =7.806159]
[ ColumnDefinition : c y l i n d e r s ( o r d i n a l ) ; [ 3 , 4 , 5 , 6 , 8 ] ]
[ ColumnDefinition : displa c em ent ( continuous ) ; low =68.000000 , high
=455.000000 ,mean=193.425879 , sd =104.138764]
[ ColumnDefinition : horsepower ( continuous ) ; low=?, high =?,mean=?, sd=?]
[ ColumnDefinition : weight ( continuous ) ; low =1 ,613.000000 , high
=5 ,140.000000 ,mean=2 ,970.424623 , sd =845.777234]
[ ColumnDefinition : a c c e l e r a t i o n ( continuous ) ; low =8.000000 , high
=24.800000 ,mean=15.568090 , sd =2.754222]
[ ColumnDefinition : model year ( o r d i n a l ) ; [ 7 0 , 71 , 72 , 73 , 74 , 75 , 76 ,
77 , 78 , 79 , 80 , 81 , 8 2 ] ]
[ ColumnDefinition : o r i g i n ( nominal ) ; [ 1 , 3 , 2 ] ]
]
Final model : [ BasicNetwork : Layers =3]
if I restart my AI, is there anyway to just apply this model to my AI without going through the whole re-train process. I'm still new to Encog as well as these AI stuff and I'm still digging so any idea will be appreciated.

Related

dupletYou are given two arrays A and B of size N and M respectively. Count number of pairs ( i , j ) such that Ai = Bj . ( 0 <= i < N and 0 <= j < M )

You are given two arrays A and B of size N and M respectively.
Count number of pairs ( i , j ) such that Ai = Bj . ( 0 <= i < N and 0 <= j < M )
Input Format
The first line contains integers N and M.
The second line contains N integers A1 , A2 ... AN .
The third line contains M integers B1 , B2 ... BN .
Constraints
1 <= N , M <= 100000
1 <= A[i],B[i] <= 1000000000
Output Format
Print one number, the answer to the problem.
Sample Input 0
8 7
1 1 3 3 3 5 8 8
1 3 3 4 5 5 5
Sample Output 0
11
Explanation 0
Total valid pairs are (0,0) , (1,0) , (2,1) , (2,2) , (3,1) , (3,2) , (4,1) , (4,2) ,(5,4) , (5,5) , (5,6).
Sample Input 1
5 6
3 4 2 2 4
3 2 3 3 5 2
Sample Output 1
7
Explanation 1
Valid pairs are (0,0) , (0,2) , (0,3) , (2,1) ,(3,1) , (3,5) , (2,5).

Response to Remote access to Unet Agents for GNURadio

I was wondering what did the Unetstack agent expect as a response to a TCP connection which is established to the modem at ip:port ?
I was trying to connect to the the modem using the TCP connection through the GNURadio pdu socket. The connection was established but i think after handshaking, it was automatically terminated. Did it expect something ?I am planning to send custom messages to modem using this APIs.
Here is what i have done so far.
I opened a TCP connection using Socket PDU block using below flow graph.
I used unet audio SDOAM to test:
jay#jay-MS-7885:~/Desktop/unet-3.2.0$ bin/unet -c audio
Modem web: http://localhost:8080/
> iface
tcp://10.0.3.1:1100, tcp://192.168.0.14:1100, tcp://192.168.0.165:1100 [API]
ws://10.0.3.1:8080/ws, ws://192.168.0.14:8080/ws, ws://192.168.0.165:8080/ws [API]
unetsh: console://- [GroovyScriptEngine]
websh: ws://127.0.1.1:8080/fjage/shell/ws [GroovyScriptEngine]
It looks like the connection was established and on GNURadio side in command prompt i got normal JSON response from modem. And Just after that connection was automatically closed. Did it expect something ?
Executing: /usr/bin/python3 -u /home/jay/Desktop/Jay/UnetstackPython.py
******* MESSAGE DEBUG PRINT ********
Send
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a l i v e " : t r u e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . G e n e r i c M e s s a g e " , " d a t a " : { " m s g I D " : " 0 9 f 5 3 2 0 0 - e 2 9 1 - 4 8 2 6 - 8 9 6 b - c 5 d 1 6 5 8 9 f 8 d 5 " , " i n R e p l y T o " : " 3 5 5 8 f e c 9 4 e e 7 b e e 1 a 5 0 f 5 6 6 1 d e 6 f c 4 b d " , " p e r f " : " A G R E E " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " w e b s h " , " a n s " : " a u t o " } } , " r e l a y " : f a l s e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . G e n e r i c M e s s a g e " , " d a t a " : { " m s g I D " : " 4 b d 5 6 f 0 7 - d a c 2 - 4 7 2 9 - 8 2 7 6 - b 4 4 1 8 6 d 3 1 6 a a " , " i n R e p l y T o " : " 8 7 7 9 5 2 4 c 4 5 d 8 9 f 1 e 4 6 3 b e 9 8 e 6 4 d 6 0 c e a " , " p e r f " : " A G R E E " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " w e b s h " , " a n s " : " t c p : / / 1 0 . 0 . 3 . 1 : 1 1 0 0 , t c p : / / 1 9 2 . 1 6 8 . 0 . 1 4 : 1 1 0 0 , t c p : / / 1 9 2 . 1 6 8 . 0 . 1 6 5 : 1 1 0 0 [ A P I ] \ n w s : / / 1 0 . 0 . 3 . 1 : 8 0 8 0 / w s , w s : / / 1 9 2 . 1 6 8 . 0 . 1 4 : 8 0 8 0 / w s , w s : / / 1 9 2 . 1 6 8 . 0 . 1 6 5 : 8 0 8 0 / w s [ A P I ] \ n t c p : / / / 1 0 . 0 . 3 . 1 : 1 1 0 0 / / 1 0 . 0 . 3 . 1 . 3 5 9 5 6 [ A P I ] \ n u n e t s h : c o n s o l e : / / - [ G r o o v y S c r i p t E n g i n e ] \ n w e b s h : w s : / / 1 2 7 . 0 . 1 . 1 : 8 0 8 0 / f j a g e / s h e l l / w s [ G r o o v y S c r i p t E n g i n e ] " } } , " r e l a y " : f a l s e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . p a r a m . P a r a m e t e r R s p " , " d a t a " : { " i n d e x " : - 1 , " v a l u e s " : n u l l , " p a r a m " : " o r g . a r l . y o d a . M o d e m P a r a m . n o i s e " , " v a l u e " : - 8 4 2 . 1 , " r e a d o n l y " : [ " o r g . a r l . y o d a . M o d e m P a r a m . n o i s e " ] , " m s g I D " : " c 4 6 8 b 2 8 c - 9 3 8 5 - 4 9 a 3 - 9 c 2 8 - a 8 6 5 e d 7 e 9 8 b c " , " p e r f " : " I N F O R M " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " p h y " , " i n R e p l y T o " : " f 9 0 a 8 1 f 2 4 4 6 6 5 2 4 8 5 c a 7 3 1 b 0 7 a 5 6 1 e 9 3 " , " s e n t A t " : 1 6 1 5 4 2 0 6 8 6 4 3 0 } } , " r e l a y " : f a l s e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . G e n e r i c M e s s a g e " , " d a t a " : { " m s g I D " : " e 2 1 2 4 c 9 c - 0 b 2 9 - 4 c 4 3 - 8 c 2 c - b 8 a d 2 3 8 c 4 1 8 a " , " i n R e p l y T o " : " 2 e 6 9 3 c b d 2 4 1 9 b 8 7 c b f a 9 c b 7 8 f 5 d 8 8 0 b f " , " p e r f " : " A G R E E " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " w e b s h " , " a n s " : " a u t o " } } , " r e l a y " : f a l s e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . G e n e r i c M e s s a g e " , " d a t a " : { " m s g I D " : " 1 e f f b 6 8 6 - a 0 5 a - 4 3 a d - a 5 a e - d 7 2 2 d 5 3 4 b b 1 9 " , " i n R e p l y T o " : " d 7 d e c 5 e b 6 a 2 3 d 6 8 3 d 6 8 2 7 3 6 2 c 8 4 d 0 2 8 f " , " p e r f " : " A G R E E " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " w e b s h " , " a n s " : " t c p : / / 1 0 . 0 . 3 . 1 : 1 1 0 0 , t c p : / / 1 9 2 . 1 6 8 . 0 . 1 4 : 1 1 0 0 , t c p : / / 1 9 2 . 1 6 8 . 0 . 1 6 5 : 1 1 0 0 [ A P I ] \ n w s : / / 1 0 . 0 . 3 . 1 : 8 0 8 0 / w s , w s : / / 1 9 2 . 1 6 8 . 0 . 1 4 : 8 0 8 0 / w s , w s : / / 1 9 2 . 1 6 8 . 0 . 1 6 5 : 8 0 8 0 / w s [ A P I ] \ n t c p : / / / 1 0 . 0 . 3 . 1 : 1 1 0 0 / / 1 0 . 0 . 3 . 1 . 3 5 9 5 6 [ A P I ] \ n u n e t s h : c o n s o l e : / / - [ G r o o v y S c r i p t E n g i n e ] \ n w e b s h : w s : / / 1 2 7 . 0 . 1 . 1 : 8 0 8 0 / f j a g e / s h e l l / w s [ G r o o v y S c r i p t E n g i n e ] " } } , " r e l a y " : f a l s e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . p a r a m . P a r a m e t e r R s p " , " d a t a " : { " i n d e x " : - 1 , " v a l u e s " : n u l l , " p a r a m " : " o r g . a r l . y o d a . M o d e m P a r a m . n o i s e " , " v a l u e " : - I n f i n i t y , " r e a d o n l y " : [ " o r g . a r l . y o d a . M o d e m P a r a m . n o i s e " ] , " m s g I D " : " f a b 5 e 8 4 8 - 4 6 7 6 - 4 1 4 9 - b 6 2 8 - 7 b b 5 a 4 8 2 a 0 f e " , " p e r f " : " I N F O R M " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " p h y " , " i n R e p l y T o " : " a d a 8 d 2 7 1 2 3 6 e 8 d 5 6 0 f 1 7 d 2 9 7 9 e 5 0 2 0 7 4 " , " s e n t A t " : 1 6 1 5 4 2 0 6 8 9 4 3 1 } } , " r e l a y " : f a l s e }
])
************************************
terminate called after throwing an instance of 'boost::system::system_error'
what(): End of file
>>> Done (return code -6)
I am trying to send this JSON message but the connection was closed before even i do anything.
Is there specific JSON response needed by unetstack to keep the connection active ?
The JSON protocol used by UnetStack is from fjåge. The full specification of the protocol can be found here: https://fjage.readthedocs.io/en/latest/protocol.html
The protocol expects an acknowledgement to the {"alive": true} JSON message within a short timeout (5 seconds). If it receives no acknowledgement, it will close the connection, assuming that the connecting party is not responsive. The correct acknowledgement is a {"alive": true} sent back to confirm that the connection is indeed alive.
The above handshake is designed to cater for other transports such as RS232 where a disconnection can only be detected by communicating over the connection.

How to make DE0-nano use ttl-232R-3V3 cable communication with PC by 1 bit(with clash-lang)?

I am trying to use the Altera DE0-nano to communication with the PC. I am using the ttl-232R-3v3 cable, currently it transmit 8 bits data once, but with the cable, it can be 1 bit a time transmit. How do I do it?
I have finish the 8 bit code:
type ST = BitVector 28
example :: ( ST , ST ) -> BitVector 8 -> (( ST , ST ) , BitVector 8)
example ( cntr1 , cntr2 ) input = ((cntr1’,cntr2’) , out)
where
sec_5 = 250000000
ascii_Y = 0x59 --ASCII for "Y" yes
ascii_N = 0x4E --ASCII for "N" no
cntr1’ | cntr1 >= sec_5 = 0 --At 50 MHz : 5 seconds
| otherwise = cntr1 + 1
cntr2’ = cntr2
out | input == maxBound = ascii_Y
| otherwise = ascii_Y
Here is the output:

How to find the direction in which the maxima of a changing array is moving in?

I have a dynamically updating array ,(changes every second).
and it consists of values from 1 to 9 . I am given a task to find out whether the maximum values are moving from left to right or right to left .
For this input the output should be left to right . The data is oncoming from a sensor and is updating the array every second .
[1 , 3 , 4 , 2 , 1 , 0 , 0 ]
[1 , 1 , 4 , 8 , 4 , 0 , 0 ]
[1 , 1 , 2 , 3 , 9 , 0 , 0 ]
[4 , 0 , 0 , 9 , 9 , 0 , 0 ]
[4 , 0 , 0 , 0 , 3 , 8 , 3 ]
[6 , 3 , 4 , 0 , 9 , 9 , 8 ]
the only way i can think of is to take the largest 3 elements in the array and sum and save their indices , if this number increases more than 2 times then we have left to right or if it decreases we have right to left movement .
Is there any other way to achieve this .
If you're writing code , python would help .thanks .
Average the indices of the maximums at each array, and then compare those averages.
You’ll have to define “moving left to right” in terms you can program, such as index_average[x] < index_average[x+1] < index_average[x+2]

How to make cipher more efficient

I have written the code for a rail fence cipher decoder, the input provided is the number of rails and the already encoded text. The decoder works, however, it only works for small inputs or short words. If i try entering a paragraph with a rails of 10 no output shows up.
I am still trying to grasp the concept of Order of a function, so I'm unsure of the order of my program. How do I make it more efficient or improve its efficiency?
Decrypt Function:
void decrypt(int rail,char *cipher) {
int length = strlen(cipher);
int i, j;
int counter=0,num=0,in=1;
int railfence[rail][100],count[100];
for(i=0;i < length;i++)
count[i]=0;
for(i=0;i < length;i++){
if(num + in == rail) in =- 1;
else if(num + in == -1)in = 1;
railfence[num][count[num]] = i;
++count[num];
num += in;
}
char buffer[1000];
for(i=0;i < rail;i++)
for(j=0;j < count[i];j++){
buffer[railfence[i][j]] = cipher[counter];
++counter;
}
buffer[length]='\0';
printf("%s\n",buffer);
}
Any help would be appreciated.
When your rail is larger than the message length, your have uninitialised string lengths for each rail. You initialise count in a loop from 0 to the message length, but you should initalise a length for each rail:
for (i = 0; i < rail; i++)
count[i] = 0;
That change should fix your error.
You are using variable-length arrays, and you know the size of these arrays. So there's no need to guess the dimensions (and make them large enough just in case). You can determine the lengths:
int zigzag[rail][length / (rail - 1) + 1];
int count[rail];
char buffer[length + 1];
(The zigzag array's inner rails have twice the number of letters in the two outer rails. Considering top and bottom rail as one, each rail must cater for at most length / (rail - 1) + 1. The + 1 at the end catches division cutoffs.)
The algorithm can probably be made more efficient by walking the message without an additional two-dimensional array. Traverse rail i with an alternating stride of 2 * (rail - 1 - i) and 2 * i. You must take care not to treat the letters of the top and bottom rails twice (when the stride is zero).
This should be considered a teaser for an optimal implementation:
if (rail == 0 || rail == railCount - 1) {
plaintextOffset = rail + offInRail * (iterfreq * 2);
} else {
if (offInRail % 2 == 0) {
plaintextOffset = rail + offInRail * iterfreq;
} else {
plaintextOffset = railCount - rail - 1 + offInRail * iterfreq;
}
}
You'll need to iterate over the rails, keeping the starting offset of the rail in the ciphertext in mind. Then you can iterate over the possible characters in the rail, while testing if plaintextOffset is not too high.
Example output using the Wikipedia plaintext as test vector:
Rails: 3, size 25
CT rail 0 : 0 + 0 = 0 <-> 0 PT
CT rail 0 : 0 + 1 = 1 <-> 4 PT
CT rail 0 : 0 + 2 = 2 <-> 8 PT
CT rail 0 : 0 + 3 = 3 <-> 12 PT
CT rail 0 : 0 + 4 = 4 <-> 16 PT
CT rail 0 : 0 + 5 = 5 <-> 20 PT
CT rail 0 : 0 + 6 = 6 <-> 24 PT
CT rail 0 : 7 + 7 = 14 <-> 28 PT (too high)
CT rail 1 : 7 + 0 = 7 <-> 1 PT
CT rail 1 : 7 + 1 = 8 <-> 3 PT
CT rail 1 : 7 + 2 = 9 <-> 5 PT
CT rail 1 : 7 + 3 = 10 <-> 7 PT
CT rail 1 : 7 + 4 = 11 <-> 9 PT
CT rail 1 : 7 + 5 = 12 <-> 11 PT
CT rail 1 : 7 + 6 = 13 <-> 13 PT
CT rail 1 : 7 + 7 = 14 <-> 15 PT
CT rail 1 : 7 + 8 = 15 <-> 17 PT
CT rail 1 : 7 + 9 = 16 <-> 19 PT
CT rail 1 : 7 + 10 = 17 <-> 21 PT
CT rail 1 : 7 + 11 = 18 <-> 23 PT
CT rail 1 : 19 + 12 = 31 <-> 25 PT (too high)
CT rail 2 : 19 + 0 = 19 <-> 2 PT
CT rail 2 : 19 + 1 = 20 <-> 6 PT
CT rail 2 : 19 + 2 = 21 <-> 10 PT
CT rail 2 : 19 + 3 = 22 <-> 14 PT
CT rail 2 : 19 + 4 = 23 <-> 18 PT
CT rail 2 : 19 + 5 = 24 <-> 22 PT
CT rail 2 : 25 + 6 = 31 <-> 26 PT (too high)
WECRLTEERDSOEEFEAOCAIVDEN
Rails: 3, size 25
CT rail 0 : 0 + 0 = 0 <-> 0 PT
CT rail 0 : 0 + 1 = 1 <-> 4 PT
CT rail 0 : 0 + 2 = 2 <-> 8 PT
CT rail 0 : 0 + 3 = 3 <-> 12 PT
CT rail 0 : 0 + 4 = 4 <-> 16 PT
CT rail 0 : 0 + 5 = 5 <-> 20 PT
CT rail 0 : 0 + 6 = 6 <-> 24 PT
CT rail 0 : 7 + 7 = 14 <-> 28 PT (too high)
CT rail 1 : 7 + 0 = 7 <-> 1 PT
CT rail 1 : 7 + 1 = 8 <-> 3 PT
CT rail 1 : 7 + 2 = 9 <-> 5 PT
CT rail 1 : 7 + 3 = 10 <-> 7 PT
CT rail 1 : 7 + 4 = 11 <-> 9 PT
CT rail 1 : 7 + 5 = 12 <-> 11 PT
CT rail 1 : 7 + 6 = 13 <-> 13 PT
CT rail 1 : 7 + 7 = 14 <-> 15 PT
CT rail 1 : 7 + 8 = 15 <-> 17 PT
CT rail 1 : 7 + 9 = 16 <-> 19 PT
CT rail 1 : 7 + 10 = 17 <-> 21 PT
CT rail 1 : 7 + 11 = 18 <-> 23 PT
CT rail 1 : 19 + 12 = 31 <-> 25 PT (too high)
CT rail 2 : 19 + 0 = 19 <-> 2 PT
CT rail 2 : 19 + 1 = 20 <-> 6 PT
CT rail 2 : 19 + 2 = 21 <-> 10 PT
CT rail 2 : 19 + 3 = 22 <-> 14 PT
CT rail 2 : 19 + 4 = 23 <-> 18 PT
CT rail 2 : 19 + 5 = 24 <-> 22 PT
CT rail 2 : 25 + 6 = 31 <-> 26 PT (too high)
WEAREDISCOVEREDFLEEATONCE
I'm not super familiar with the algorithm, but it seems like you could save a bunch of time and memory if first you found the length of the string, then found the number of spaces (possibly using this), subtracted those two numbers, and then divided by rail (let's call the resulting number numCols). Then you'd just create one 2D char array, with rail rows and numCols columns. Go through with two for loops (columns nested inside of the rows) inserting the characters in order (making sure to avoid spaces).
Once you've done that, just read them back out, except this time, nest your rows loop inside your columns loop.

Resources