Author Topic: Application of a "Bias" in AI Programming  (Read 7894 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Application of a "Bias" in AI Programming
« Reply #15 on: September 10, 2018, 12:46:37 pm »
As I understand the situation (from one very lame starting exercise) Bias is just one more Input what I call "link" into Perceptron.

The Perceptron takes all the links and multiplies by weights to get a Sum and then that Sum is used in an "Activation Function" (in example just a Sign function that is + 1 if sum >=0 else -1)  to determine what the Perceptron will output for that set of links, in the example +1 or -1.

The Bias * BiasWeight was just one more link to add to Sum, you might call it a Constant Link, In the example, the links were x, y coordinates of a point.

Near as I can figure out, Bias is a fix that you need to convert a string label to a number. Since we can't multiply a string (a link label) times a number, we use numbers to represent the links. A coordinate system is very convenient to label links, but the origin 0, 0 would Sum a weight of 0 whether it is important or not, (0, 0) is  not trainable. So the Bias is added so that the point  (0, 0) can be trained as any other point also (0, y) and (x, 0) might have distorted weights without balancing effect of Bias * BiasWeight.

I am calling the inputs, links, based on drawing of Perceptron: two lines INTO (the x, y coordinates in lame example) one line OUT = Perceptron's evaluation of sum from links. Each link has an importance for deciding the pattern that is the weight the training tries to establish, so you have a value associated with a label of link.

I am calling example lame because yesterday afternoon I started working on problem of digit recognition, so that requires getting digits 0 to 9 trained and saving the weight data for testing against a pattern to identify, the best match wins.
I had some difficulty and confusion getting digit images to fit in 60 x 60 cell array. I thought I messed up something because they were smaller than I thought they would be even though I was multiplying 1 pixel by 3 square cells. I then drew frames around digits (in more +1 -1 cells to train for) to see that I had it right. But with frames around digits, the training couldn't get past 92% for digits 0 and 2 and probably 8, 9... double and triple "enclosures" are hell for array "rays". You really need to assign a weight the every single (x, y) point NOT a weight for x = 1 to cellW, y = 1 to cellH  = 60 + 60 + (1 for Bias) weights is how the lame example is doing it.
You need 60 *60 + (1 for Bias) weights for points (not x, y lines) will get the training done and in one pass!
and then you don't even have to train! ;P

So as far as digit recognition goes, I would go about the task in a completely different manner starting with the problem of getting an image you want to ID centered and aligned with your model of the thing you are trying to ID.

Yeah, the pregnancy test was a humorous attempt to overcome this dry and boring example of Y>= X. ;-))

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Application of a "Bias" in AI Programming
« Reply #16 on: September 10, 2018, 05:35:28 pm »
I've been trying to run your program but keep getting an out of range error in that "sum= x*WX(x) + y etc" line of the Perceptron functon. At the moment just can't find what i've entered incorrectly. A lot here to chew on, especially when the AI program has to deal with images and co-ordinates. You have captured a lot from that " one very lame starting exercise". Today 0 to 9, tomorrow everything that casts a shadow. As for that pregnancy test, I'm determined to get your program up and running just to trigger that one response. Have plans of having my wife casually run the program. Thanks again bplus, i very much appreciate your "link" or input, unbais as it may be.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Application of a "Bias" in AI Programming
« Reply #17 on: September 10, 2018, 07:35:36 pm »
I tested a copy paste from forum and it runs as should. Are you running on Linux?

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Application of a "Bias" in AI Programming
« Reply #18 on: September 10, 2018, 09:53:45 pm »
No, I'm windows 10.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Application of a "Bias" in AI Programming
« Reply #19 on: September 10, 2018, 10:52:34 pm »
Hi Dimster,

I am using Windows 10 64 and tested a copy paste of the code I posted here in QB64 versions:
v1.2 2018 0228/86 git 6fde149

v1.2 2018 0228/86 git b30af92

and v1.1 2017 1106/82

they all worked fine.

You must had advertently or inadvertently changed something. ???





Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Application of a "Bias" in AI Programming
« Reply #20 on: September 11, 2018, 09:21:05 am »
Not sure what you mean by a copy paste of the code? I have copy and printed out the code you posted, then wrote line by line into my version of qb64. I'm not sure if you have more than one version posted somewhere else??

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Application of a "Bias" in AI Programming
« Reply #21 on: September 11, 2018, 09:55:23 am »
Hi Dimster,

Did you know you can copy what is posted here at forum and paste it directly into QB64 IDE editor and run the code usually without having to even save the file first (unless the code works with external files). That is what I thought you were doing so it would be strange to find the exact same code working at one Windows 10 computer not working on another unless our versions of QB64.exe are different.

I have copies with mods scattered all about that is why I test the code I had posted when hours have passed since posting.
I am always modifying, always trying to improve or magnify some aspect of the code idea.

My guess with range problem is that the array variables for the lbound and ubound limits of array (or array DIMensions itself) have been changed so they no longer match each other. I was working with the lower range at 1 because it displayed better and got away from 0's in weight calculations.

Here I set the variables for lbound and ubound of the array first, then DIM array with the varaibles eg
lb = 1 : ub = 100 : dim array(lb to ub)
« Last Edit: September 11, 2018, 10:03:10 am by bplus »

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Application of a "Bias" in AI Programming
« Reply #22 on: September 11, 2018, 12:02:16 pm »
Thanks bplus - I had no idea I could paste directly into the QB64 ide editor. Your program works perfectly. Geez, live a little, learn a lot. There are so many more programs that i could have been running - feels like Christmas. Very, very much appreciate your directions here.