Showing posts with label My Projects. Show all posts
Showing posts with label My Projects. Show all posts

Friday, 20 April 2012

Intelligent Agents in a simulated environment

The following video and the description is about a Agent simulation that I have designed and implemented. I would like to give my gratitude to the "Intelligent Agents" module director 
Dr. Sam Steel at the University Of Essex for his supervision throughout the module.

The simulation shows an "Agent-world" represented by a grid of squares. Agents survive in this world by eating plants. There are four types of plants that occur in various quantities. Agents are able to consume a combination of plants and gain more energy. The energy levels decreases as they live and as they roam to other squares in the gird. Creatures can carry a limited amount of plants so then can eat when it is needed. If the creatures can create two combinations at once then the most energetic combinations of plants will be eaten first.



In the “Agent world” there could be maximum of two types creatures in the world.

The agent types:

SimpleCreature: Less intelligent creature.

IntelCreature: Most intelligent creature.

SimpleCreature:

A simple creature will be born in the agent world with a limited amount of energy. The creatures move around the world in random directions in a consecutive manner, for random amounts of times, with an intention to feed to survive. A simple creature can carry a limited amount of plants. This creature eats plants when it's energy goes down less than it's energy limit. (When it feels hungry) The creature is able to consume compounds(CP)of plants (P) of varied types (t) that they carry, and gain more energy than it would if it eats them individually. Such that:

CP = {Pt1, Pt2, Pt3, Pt4}

Creatures can only see the plants in the same square as it is. When the world has been resized, eventually the creatures will follow back in to the world. Each individual creature has got a unique ID. This phenomenon has been recorded on the video.

The simulated environment in which the creatures act:
The “Agent world” is a grid of squares. The plants and the creatures will be in this grid.


IntelCreature: 

Only an IntelCreature can look around. These creatures can only see only one square around ahead, as well as the square it is interpolated. They can also see the the plants as well as the creatures in its range of vision.



The creature can remember the creatures and the plants in the squares that it can see (This memory is limited). Although the vision is perfectly accurate only within its local square. Just after it has been born, IntelCreature will be in an Observation mode, so that it will observe the world by capriciously observing the world until it finds more than one plant. Then it will start going after the plants intentionally that it sees around. A creature may decide to go after plants that are more therapeutic than the others. Such plants may be the plants that could complete a combination.

If two creatures meet together in one square they start talking to each other, asking about the plants that the other creature carry. Then the first creature will propose to the other creature for a shared combination, with the amount that it would like to share. Such that:

Assume:
combo1 = P1 + P2 + P2
Ag1:Plants = {P1, P3, P3, P1}
Ag2:Plants = {P2, P2, P3}

Then:

Ag1: Ag2.requestCombo(<share_amount>, <plant>)

If the other creature agrees then they will consume the plants and share the energy amount. When they share the plant combinations, they will get the double the amount of the normal combination, hence it is more desirable for the creatures to share. The creatures can decide to be partners with another one, and go for other plants that one of the creatures have seen. Furthermore when the creatures are in the same square, they may request other creatures to be parters, a creature will request to be a partner of another creature, if the plant the second creature is going after, interests the first creature. If the second creature agrees to be partners, then it will make a leader and partner relationship between each other. The first creature that made the request will be the partner and the other will be the leader.  After the leader gets the plant, the energy amount will be shared. Finally the partnership will end and the two creatures will go their own ways. In the situations where the plants that are subject to the partners engrossment have been taken by some other creature, the partnership will immediately end. When the partnership has been made, the colour of the red circle, will change to a light yellow colour if it is a partner, and the colour of the leader's circle will change in to dark yellow. This is demonstrated in the figure blow.


A creature can make partnership with another one, only if the both of the creatures are neither a partner or a leader. If the creatures do not carry any plants and it can not remember any plants, it goes back to the Observation mode to collect information about the world(Grid). If the creature can not carry any more plants, it will stop travelling to save the amount of energy that it will loose by going to other squares.

What are plants?:
  • There are four types of plants in the world.
  • Green plants, Red plants, Yellow plants, and Magenta plants.
  • The plants are represented in small squares with the colour of their names.
  • Each plant holds different energy levels.
  • A plant set consists of a set of random types of plants.
  • The plant sets appears in the “Agent world” in arbitrary places.
  • The amount of the plants that will be put in to the grid is variable. 
  • In the world there will be a constant amount of plants at a time.
  • The size of the “Agent world” is variable.
  • The number of types of plants are in the world are variable.
  • The energy of creatures will be consumed until it dies. The energy consumption speed is variable.
  • If the creature moves to a different square, more energy will be consumed than if it stays in the same square.
The log output of the software which show
  • what a particular simple creature does
  • what a particular creature that looks around does
  • the interaction of a two creatures who meet 

The above description about the "AgentWorld" is just a brief introduction about the project. Accordingly there are many other theoretical and technical details that I have not introduced to you in this article. Although if you are interested, I am happy to supply you with further details on this project.

Wednesday, 4 April 2012

Content Based Image Retrieval using cross correlation co-efficiency

Have you ever searched google for images? I am sure everyone who is reading this article has done this before more than once. Wouldn't it be nice if you could search images for the similar images, for a given image? So for an example, if you want to search for an image of a particular object, by supplying a probe image (a image which to find similar images of) to the search engine, you can search for images that are similar to the given image.

Content-based image retrieval (CBIR) or Query by image content (QBIC), is an active area in Computer Vision research. Comparing images using cross-correlation efficiency was similar to the state of the art for CBIR in the early 1990s. Comparing the colours in the probe image and other test images, is one conservative way of doing this. Histogram is a good way of discriminating the colours in an image.

One way of doing this is explained below. There are many ways of doing this although this is not necessarily the right or the best way of doing it.

  1. Split the R,G,B channels of the probe image
  2. Split the R,G,B channels of the "test image" that is subject to comparison.
  3. Calculate the histograms of the R,G,B channels of each images.
  4. Calculate the cross correlation of the R, G, B channels of the probe image and the "test image" histograms. Such that, 
    r1 = correlation(img1.R,img2.R);
    r2 = correlation(img1.G,img2.G);
    r3 = correlation(img1.B,img2.B);

     5. Finally multiply the results all together ( r1 x r2 x r3 )

The result (r) of a cross correlation calculation lies between -1 and +1. If the value is +1 in average the two images are identical. If it is -1 then the images are identical but the image looks like a photographic negative version of the probe image. If r=0 then the images are on average very unlike each other.

People who are interested in Computer Vision are likely to be familiar with the OpenCV library. The following code snippet (incomplete) is an example for calculating the cross correlation co-efficiency using the OpenCV library in C.


  //split img1 in to RGB channels and store them in seperate images

  cvSplit(img1, img1R, img1G, img1B, NULL);

 

  //calculate histograms of the the image

  CvHistogram *h1R = calHistogram(img1R, bins, ranges);

  CvHistogram *h1G = calHistogram(img1G, bins, ranges);

  CvHistogram *h1B = calHistogram(img1B, bins, ranges);



    //split the image two in to RGB channels and store them

    //in seperate images

    cvSplit(img2, img2B, img2G, img2R,0);

   

    //calculate histograms of the RGB channel images of the "img2"

    CvHistogram *h2R = calHistogram(img2R, bins, ranges);

    CvHistogram *h2G = calHistogram(img2G, bins, ranges);

    CvHistogram *h2B = calHistogram(img2B, bins, ranges);

      

    //Calculate the correlation coefficient of RGB images, of img1 and img2

    rR = cvCompareHist(h1R,h2R,CV_COMP_CORREL);

    rG = cvCompareHist(h1G,h2G,CV_COMP_CORREL);

    rB = cvCompareHist(h1B,h2B,CV_COMP_CORREL);

    

    //Multiply the results together

    tempR= rR*rG*rB;




The performance:

Some performance evaluation has been done on this program using a test harness called 'Fact'.

Error rates calculated from mycbir
tests TP TN FP FN accuracy recall precision specificity class
8 0 0 8 0 0.00 0.00 0.00 0.00 box
8 0 0 8 0 0.00 0.00 0.00 0.00 cockeral
8 6 0 2 0 0.75 1.00 0.75 0.00 dog
9 7 0 2 0 0.78 1.00 0.78 0.00 horus
8 7 0 1 0 0.88 1.00 0.88 0.00 ornament
10 8 0 2 0 0.80 1.00 0.80 0.00 penguin
8 1 0 7 0 0.12 1.00 0.12 0.00 reindeer
9 2 0 7 0 0.22 1.00 0.22 0.00 tortoise
68 31 0 37 0 0.46 1.00 0.46 0.00 overall

TP = True Positives
TN= True Negatives
FP = False Positives
FN= False Negatives


In the matrix above it shows the amount of test cases for the each picture in the “test” column, True Positives, True Negatives, False Positives and False Negatives in the next four columns.  Then the application calculates the accuracy, recall, precision and specificity as follows, and displays in the next four columns. The last “class” column show the type of picture that it has carried out the test on,

Precision is the number of relevant pictures that are retrieved, divided by the total number of of pictures retrieved. Recall is the number of relevant pictures retrieved divided by the total existing relevant pictures. The specificity and the accuracy is calculated as below



                                      TP                                                                        TN                                    
sensitivity = recall = ------------------                                       specificity =     -----------------
                                TP + TN                                                                   FP + TN

 As you can see above, the application has failed to find the True Positives for the “box” and “cockeral” pictures. So in contrast it has found False Positives in all cases. The best case is the tests on the ornament pictures as it has found 7/8 TPs and 1/8 FPs. Overall this algorithm has done 68 test cases and have found 31 True Positives and 37 False Positives, but no True Negatives or False Negatives.
The matrix below, is the class confusion matrix.

Confusion matrix calculated from mycbir
expected
actual box cockeral dog horus ornament penguin reindeer tortoise
box 0 0 0 0 0 0 0 1
dog 0 0 6 0 0 0 0 0
horus 0 0 1 7 0 0 0 4
ornament 1 1 0 0 7 2 7 0
penguin 1 0 0 0 1 8 0 0
reindeer 5 7 0 1 0 0 1 2
tortoise 1 0 1 1 0 0 0 2

The columns and rows indicates that, the classes in the rows titles were obtained when the classes in the column title should have been found (Rows as obtained results, columns as expected result). The numbers indicates the number of times it has been obtained. So as an example, as the worst case: in the “box” column,

ornament =1, penguin = 1, reindeer = 5, tortoise = 1 has been obtained when “box” pictures should have been found. But it has not obtained any “box” pictures as the value of the “box” raw is 0.

As I have mentioned earlier the best results has been obtained on the tests with the “ornament” picture. It has obtained the correct “ornament” pictures 7 times and a penguin picture just one time.

Conclusion:

Cross correlation is not the best Content based Image Retrieval technique to date, though it helps us to understand how the histograms of two images can vary or can be complementary. But it is no doubt that analysing just the colours in images are a good way of characterising them though it is hard to compare two images using just this factor.

Tuesday, 12 April 2011

Text Encryption Application

Under the Computer Security module we did one last assignment at the end of the term, the assignment was to implement the substitute cypher and demonstrate how it can be broken by using Frequency Analysis. So I have written a code to encrypt some text using a key, which the user inputs to the application (Which the application assumes that the key is unique), and to Break the encryption using frequency analysis, using Java. It was required to leave the spaces and non alphabetic characters, and maintain the cases in the cipher text (which makes the cypher text weaker).

I have added another extra feature for the cipher breaking code called The "Advanced Frequency Analysis". Which means that, In frequency analysis it just analyses the frequencies of single characters. But if you turn on this feature if will analyse two and three character combinations as well as single characters, which makes the code breaker more strong.

You will probably wonder that why would I want to add extra code to make the encryption weak. As an example this program passes spaces, non alphabetical characters through to the cipher text. It is because that they are requirements of the assignments so students can write about it on the report and give explanations about how to make it more stronger.

Find the screen shots and examples of the program below.

Encryption

Plain Text:

Data centres use vast amounts of electricity to run their computer equipment and also to keep it cool.

Environmental group Greenpeace has estimated that their total global energy use will have reached 2 trillion kw/h by 2020.


Key:

qazxswedcvfrtgbnhyujmkiolp




Cipher Text:

Hjtj koetfor gro bjrt jwdgetr dl osoktfakaty td fge tqoaf kdwcgtof ovgacwoet jei jsrd td xooc at kdds.

Yebafdewoetjs pfdgc Jfooecojko qjr ortawjtoi tqjt tqoaf tdtjs psdmjs oeofpy gro nass qjbo fojkqoi 2 tfassade xn/q my 2020.


Decryption

Advanced Frequency Analysis = off


Decrypted plain text:


Kata lestier dre wart amodstr oq eheltinlntg to ids tueni lomc1dtei ezdnc1mest asf ahro to veec1 nt looh. Jswniosmestah yiodc1 Xieesc1eale uar ertnmatef tuat tueni totah yhopah eseiyg dre bnhh uawe iealuef 2 tinhhnos vb/u pg 2020.


Advanced Frequency Analysis = on



Decrypted plain text:

Kata lestier the wart amodstr in eheltinlntg of for tueni lomc1dtei ezdnc1mest and ahro of veec1 to looh. Jswniosmestah yiodc1 Xieesc1eale his ertnmatef tuat tueni totah yhopah eseiyg the bnhh uawe iealuef 2 tinhhnos vb/u it 2020.



My Example is just a simple demonstration. As you can see its hard to analyse and decrypt just by using an application/ Algorithm, without having any human help. But This algorithm works better as the plain text gets larger, as it gets more data to analyse so the accuracy of the analysis gets better.

Monday, 11 April 2011

My Tetris

'Tetris' is one of the most popular games of all time. For the last project of Application Programming module at the university, I got to develop this small Tetris game applet. As you can see its very basic and simple as I added more than requirements of the assignment, to the application itself. It would have had more functionalities but I moved on from it to the next assignment so I can finish my assignments and get it everything done way before the deadline. I will add more features to it if I get much time in the future, even though I tried ones and then I got busy with something else and then moved on.

To control the blocks You can use either keyboard or mouse or both.

Controls:

Mouse Controls:

Right-Mouse Button- Move right
Left-Mouse Button - Move Left

Key Board Controls:

Right Arrow key- Move Right
Left Arrow key - Move Left
'R' key - Rotate

If I develop it more further I will definitely post it on here. Like I have said it earlier its a very simple version of Tetris. But it plays according do all Tetris rules.


Wednesday, 7 July 2010

John Conway’s Game Of Life

  

    Game of life  is devised John Conway is a British mathematician John Horton Conway in 1970. As a part of my last Java assignment I re designed and added more components to the game under the Java lecturer Professor Simon M. Lucas’s guidance. I was really excited to make this application just after seeing Simon’s example of the Game Of Life.

 

Rules:

The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, live or dead. Every cell interacts with its eight neighbours, which are the cells that are directly horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

 

  1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  2. Any live cell with more than three live neighbours dies, as if by overcrowding.
  3. Any live cell with two or three live neighbours lives on to the next generation.
  4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed—births and deaths happen simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the one before). The rules continue to be applied repeatedly to create further generations  

-Wikipedia-

 

 

 

             Untitsdfsledd

 

You can create your own rules by changing the bits on the bit editor in the right hand side. You can stop and Resume your game anytime by just pressing the Start/Stop button. By changing bits you can create really cool patterns on the game window. As an example the following picture shows one of the rules I have made

 

             Untitsdsdfdfsledd

I won’t talk about the Java code and the logics of this program but If you want to know or if you want to play this game,  just email me or leave a comment. I’ll send you more information

 

Thank you for visiting My blog

Scribble

 

   Scribble is a painting pad which enables you to draw really cool patterns on it. I made this peace of application as a part of the java assignment under the Java lecturer Professor Simon M. Lucas’s guidance. It’s been a great experience to make this application.  It was a great experience to make Scribble. I was quite excited to see the end product after seeing completed application in the Lectures. I have completed the whole assignment successfully before the dead line and I am glad that I have got quite high marks for it and I have got full marks for this part of the assignment Open-mouthed smile. I will soon post the other past of the assignment and it will be my next blog post.I have posted some random things I drew on it so you can get an Idea about what it looks like. Hope you will like it.

 

 

 

 

                       Untitsdfsledd

 

 

 

                        Untitsledd

 

 

                       Untitled

 

 

 

I wont post anything about the Java Codes of this application but if you want to know about it or if you want to try this application by yourself,  just email me or leave a comment.

 

Thank you for visiting my blog

 

-Chathura Mazz-

Tuesday, 29 June 2010

My Tunes

 

 

This is instrumental track is one if my favourite tracks I have made. Sorry I haven’t named this one either. I’ll name it if you can come up with a good name.

 

Enjoy

 


My First FL Studio Project

 

   This is the first track made using FL studio. Sorry I haven’t named it yet but let me know if you have any ideas.



Enjoy

 



Another Tune

 

I just thought I would post this tune I made years ago. So I exported the  audio file off from FL Studio. hope you will enjoy it


Sunday, 14 February 2010

The Lollipop remake

I just thought I would post this tune I made. This is a rock version of the song Lollipop by Lil wayne. I am not a musician but I just wanted to try this software called Fruity loop. Hopefully I will post more instrumentals in the future Hope you all enjoy it.

Press Play>>>