Lunarium 2 : Machine Learning Agent experiment Day 1

Top Tent Scene


The alienated death character has three pipes with eyes that flip up and down as air is forced through them (Think Pipe Organ). The concept was inspired by carnivorous plants that omit a sonar signal to attract bats. 

I want to create a bat Agent that will find the location of various carnivorous plants in the environment, and once all have been found, this will trigger the alienated death character to play the death march music.   

I have found a tutorial that explains how to create ML Agents. It effectively trains a hummingbird to locate nectar inside flowers in the environment. I think I can use this in my own project to train a bat to find and infect carnivorous plants. Once all are found and infected this will trigger the alienated death character to play the music and open the exit to the level. The ML Agent mechanic will act as a kind of timer.

I have set up the flower script, the flower area script and the hummingbird script so far.   

The code returned a number of errors which I think relate to how the code over rides Agent code, of which initialize is one. Apparently, It will still function but this won’t be evident until the script is applied and the game run. 

Errors

Initialize

Transform 

GetComponent

GetComponentParent 

OnEpisodeBegin

OnActionRecieved

Heuristic

AddReward


// Calculate reward for getting nectar

float bonus = .02f * Mathf.Clamp01(Vector3.Dot(transform.forward.normalized, -nearestFlower.FlowerUpVector.normalized));

AddReward(.01f + bonus);

The rewards must balance out to equal positive 1. This just needs trial and error to figure out. 

Give a reward for collecting nectar but take away reward if banged into too many walls. 


What is a .dot product ? 

  // Observe a dot product that indicates whether the beak tip is in front of the flower (1 observation)

  // (+1 means that the beak tip is directly in front of the flower, -1 means directly behind)

sensor.AddObservation(Vector3.Dot(toFlower.normalized, -nearestFlower.FlowerUpVector.normalized));


Unity’s description of a .dot product. 

Dot Product

The dot product takes two vectors and returns a scalar. This scalar is equal to the magnitudes of the two vectors multiplied together and the result multiplied by the cosine of the angle between the vectors. When both vectors are normalized, the cosine essentially states how far the first vector extends in the second’s direction (or vice-versa - the order of the parameters doesn’t matter).

It is easy enough to think in terms of angles and then find the corresponding cosines using a calculator. However, it is useful to get an intuitive understanding of some of the main cosine values as shown in the diagram below:-

The dot product is a very simple operation that can be used in place of the Mathf.Cos function or the vector magnitude operation in some circumstances (it doesn’t do exactly the same thing but sometimes the effect is equivalent). However, calculating the dot product function takes much less CPU time and so it can be a valuable optimization.



NOTES  

The ML Agent could be used as a mechanism to create a 'daisyworld' simulation that demonstrates the earths homeostasis. If you are not familiar with this concept, check out the gaia theory. Essentially when black flowers number more than white the earth absorbs more energy and heats up but when more white flowers are in higher numbers than black, the earth reflects energy and cools down (Like the ice fields at the north pole acts as a mirror.. which it could be said is currently is in a runaway state). It could also be used to represent the bee population and flower polination or human population and earths resources, or potentially the current pandemic (and all of the above). 




  

Popular posts from this blog

Metahome Development

Seraphina Stormrider