Monday, July 29, 2013

Rat Brain

I've been working on a Neural Network I like to call the Rat Brain.  In the past, I've played with neural networks that used forward propagation and although they work, they require an insane amount of training to properly weight all of the nodes.

I read a book by Jeff Hawkins called On Intelligence and I wanted to see if I could write an AI that learns more like a human than a pre tested neural network.  So, the Rat Brain Project was born.  Not this one, but I thought I would reference it because this is actually a Rat Brain driving a car.

The first test is to have an object (Blue Box) on a rope that is of fixed length.  There is a hunk of cheese (yellow box) on one of the sides of the rope.  The robot brain must learn to go to the cheese.  The interface looks like this:
  1. Distance to one of the sides.
  2. Hunger (Internal Desire)
  3. Left Vision: (True or False) Can I see the cheese on the left side?
  4. Right Vision: (True or False) Can I see the cheese on the right side?
  1. 00: Stop
  2. 01: Right
  3. 10: Left
The rat can definitely get the cheese.  Right now I have successfully been able to have the brain map the nodes as designed.  I haven't added any of the other inputs yet, but it will go back and forth forever.  This is the node tree that is generated:
At any time during the test I can hit the pause button and look at the node tree.  I'm also generating extensive logging.

So, this may look like a lot of nodes but there are really only three memory nodes (Orange circles).  The inputs are the first circles on the top, and the single output (O1) is on the bottom.

My future tasks will be to introduce the additional inputs and problem solving.  I'm also missing degradation of the connection strengths and nodes over time.  The system should store sequences into short term memory but release that information if a better path is learned.  There is a lot of work to do still but it is a fun project.  If anyone is interested in talking shop with me let me know and I can start posting the algorithms and node designs.

Happy Coding!

Friday, April 19, 2013

From .NET to Java

I started studying code development in Java using Eclipse and decided to blog a little on my experience.

So far I have built three different applications. 
  1. A console application.  I followed the tutorials here:
  2. A Hello World GUI Application.  Using Swing, I was able to plop a label and a button on to a form in the designer.  It was very easy to figure out how to hook up an event and set the label text when clicking the button.  But, I have to say that this designer was pretty bad.  So if you know of a better one please let me know in comments.
  3. A Servlet: I found a video that walked me through adding a servlet and choosing an Apache Tomcat v6.0 virtual server.  This part I really liked.  Writing the servlet to return some html was pretty simple.  There seems to be a lot of files that were created so I will begin to go through their functions.
Next Steps:
I will begin looking into deploying my servlet and looking at JSP.  After that, I'll try to hook up my sample to a database to push and pull some data.

I will start blogging some of the tips that I learn along the way. 

Happy Coding!

Friday, October 26, 2012

Indie 3D Project Promotion

RightBytes is sponsoring three 3D projects! If you are part of a small project team or a 3D hobbyist and are interested in software that is easy to use, sign up for a beta copy! Receive the latest version of Artismo for your team as well as exposure on our site.
Some features of Artismo are:
  • Polygon Modeling System.
  • UV Mapping.
  • Layer System for Model Design.
  • Bone Animation System.
  • UV Envelopes for Vertex UV Assignment.
  • Integrated 2D Art program for producing seamless textures and 2D assets.
  • SpriteMaker Plug-in: For exporting 3D animations to 2D sprite animations for 2D engines and mobile support.
Export Formats:
  • .X file (Animated and Static) for DirectX and XNA Projects.
  • STL: 3D Printer Bot files for 3D Printers.

Sunday, October 02, 2011

Artismo on Windows7

Artismo is working on Windows 7. It turned out that I had optimized some of the core code and forgot to update the installer to include the new dll's. So, we're back up and running.

I started another project working on a Content Management System. I should be using this system on the new Artismo Site to start testing the beta. The CMS is written in C# using MVC3.

Happy Coding!

Saturday, June 18, 2011

.NET Workflow WF4 State Machine Activities

You may have noticed that workflow has changed drastically from WF 3.5 to WF 4.0. You may have also noticed that the state machine activities were not shipped with WF 4.0.

Fortunately, they have been released on Codeplex. So, here is a link to download the update.
Workflow 4.0 from Codeplex as part of a service pack

I've been playing with the new Workflow and let me say I really like it! Good job WF guys at Microsoft!

Happy Coding!

Saturday, June 11, 2011

WCF, Entity Framework, and LINQ in 15 Minutes

In this tutorial we'll use Entity Framework in VB.NET to create a Data Model from our SQL database. Then, we'll create a WCF Service to fetch a customer using LINQ. Finally, we'll create a Windows Form as a client application to call the WCFService and get back some data.

-Visual Studio 2010
-Sql Server Express
-Sql Management Studio (Installed with Sql Express)

1. Creating the Database

To create a simple database for this tutorial:
  1. Open Microsoft Sql Server Management Studio.

  2. Right-Click on the databases folder and choose New Database. Name the database "Testeco".

  3. Right-Click on Tables and choose New Table. Create a table with the following columns:

    IDPrimary key, datatype as numeric(18,0) and allow nulls false. Set Identity to true in properties of column.

  4. Name the table "Customer" and hit Save. I named mine "tblCustomer" out of habit, but if you usually prefix your database objects (e.g. tbl, vw, sp) you may want to stop doing this because these names now bubble up into the object names in the solution.

  5. Right-click your table and choose "edit top 200 rows" which will bring up an interface to add rows. Insert five test rows, hit Save and your database should be ready.
2. Creating the Solution

Open Visual Studio 2010. Create a new project. Under Project Templates Choose Other Project Types->Visual Studio Solutions: Blank Solution. Name your project "Testeco" and hit OK.

3. Creating the Data Model Project
  1. Right-Click your Testeco Solution and choose Add->New Project.
    Choose the Visual Basic->Class Library and name it "Testeco Data Model" and hit ok.

  2. Delete the Class1.vb file.

  3. Right-Click the new project and choose Add->New Item. From the list select ADO.Net Entity Data Model, and name it "TestecoDataModel" and hit ok.

  4. A dialog box will appear. Select "Generate from Database" and hit next.

  5. The next dialog requires that you specify the database connection. Select new connection. If you're using sqlexpress you will type the name of the database as localhost\SQLExpress. Select the testeco database and hit ok. Save the connection string as "TestecoEntities" and hit next.

  6. To select the database objects, drill down to tables and check the Customer table. Uncheck the option for Pluralize or Singularize generated object names. This option is not working correctly in the current version but is supposed to be fixed on the next service pack. Name the namespace as "TestecoModelContext" and hit finish.

At this point, you have an Entity Framework Data Model of your table. You should see a new file called TestecoDataModel.edmx and a diagram of the data model in the designer. It has generated the classes to handle updating the database with your object changes for you. Now we are ready to use that data in a service.

4. Creating the WCF Service

In this step we will create a web project that will host our WCF Service.
  1. Right-Click the new project and choose Add->New Item.
    Select WCF->WCF Service Application from the options, and name it "WCFTestecoService". Hit OK.

  2. Delete the IService1 and Service1 files as we will be creating new ones.

  3. Select this project, right-click and select Add->New Item and select WCF Service. Name the file "WCFTestecoService" and hit Add. It creates the Data Contract(Interface) and Service which implements the contract.

  4. Open the Data Contract called "IWCFTestecoService". It created a sample function called DoWork which we will replace with a function to fetch a customer from our Data Model. Replace the Sub DoWork function with:

    Function GetCustomer(ByVal id As Integer) As Customer

    The compiler will flag the return type Customer as unknown but we will fix that on the next step.

  5. Right-click on the project and add->Class... and name it Customer. At this point our compiler will be happy about returning a Customer type. But, we need to add two public properties to the class file. Add two properies to the Customer file for Last and First making your class look like this:

    Public Class Customer
    Public PropertyFirst As String
    Public PropertyLast As String

    End Class

    Something to keep in mind here is that this is not the same class as the Customer coming out of the Entity Framework. We are creating a simple wrapper to return from the service.

  6. Open the WCFTestecoService file. There should be a function in there still that says dowork. We need to rewrite this function so that it implements the new constract we created. Just delete the dowork function completly, place your cursor at the end of the line that says: Implements IWCFTestecoService and hit enter. It will reimplement the interface in your class and write the new function GetCustomer.

  7. Now we need to write the function to get the data out of our datamodel. But, we need to add a reference to the data model project. Right-Click on your service project and select Add Reference. A dialog will appear. Make sure the Project tab is active and select TestecoDataModel and hit OK. We have now added the reference to our data model project.

  8. Back to the GetCustomer function, we need to instantiate the datamodel to query against. Add the following to your function:

    Public Function GetCustomer(ByVal id As Integer) As Customer Implements IWCFTestecoService.GetCustomer
    Dim context = New TestecoDataModel.TestecoEntities()

    Dim result = (span class="blue">From cust In context.Customers
    Where = id
    Select cust).First

    Return New Customer() With {.First = result.First, .Last = result.Last}

    End Function

    When you update your function two things need to be checked. First, it may complain about the context.Customers. If so, remove the .Customers and use intellisense to add the proper table name (yours may be a little different than mine). Next, it will pick up a missing reference. if you click on the error it will tell you you're missing a reference to System.Data.Entity. And if you click it, it will fix it for you. Great tool!(Wishing C# did this..) The code should now compile correctly. But, before we move on let's review this code.

    The context is our datamodel. We are using Linq to query the context for a customer with a matching ID. We are returning a new customer and setting the properties of the object before we send it back.

  9. One last thing to do is to copy the connection string from our app.config file in the EntityFrameWork project into the web.config for our WCFService. Copy the connectionstring tag out and paste into your web.config. Now, our code can properly reach into the configuration for the connection string it will need.

  10. Build the entire solution and make sure it compiles.

5. Creating the Client Application

We will use a windows application to consume the WCF Service and provide an interface to get our data.

  1. Add a new project to your solution and choose type Visual Basic->Windows->Windows Forms Application and name it ClientApp.

  2. Create a simple form that looks like the image above.
    Name the textboxes as txtID,txtFirst, and txtLast.

  3. We need to add a web reference to our WCF Service. We do this by right clicking the project and selecting "Add Service Reference" which will bring up a dialog. Click the Discover button which will find your web project. Click on the little arrow next to TestecoService.svc which will show our service contract under it. Selectit in the left (nothing will appear in the right which is okay) Name it TestecoService.

  4. Double-Click the Go button on your form to go to the gobehind code. We need to write code that will take the data form the txtID.Text, get a result from our service, and load it into our textboxes. The function should look like this:

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
    Dim svs = New TestecoService.TestecoServiceClient

    Dim cust = svs.GetCustomer(CInt(txtID.Text))

    txtFirst.Text = cust.First

    txtLast.Text = cust.Last

    End Sub

    We first get a reference to a proxy class that was generated when we added the reference. we then call the function and get our data back. That's it.

  5. Set the startup project as your ClientApp project and run the program.
So, in a few minutes we've used the Entity Framework to create a data model, which we accessed using LINQ in our WCFService, that was used in a simple windows application.

Happy coding!

Wednesday, April 20, 2011

3D Boolean Operations

A Boolean operation is a process of creating a result set from combining two 3D objects. In this case, I'm creating the union of the two objects. See the picture above of the latest output from the algorithm i'm writing.

It has been challenging to say the least. You have to calculate intersection between the objects for both coplanar (flat surface) and nonplanar scenarios. Once this is done you must triangulate the triangles and then sort them and return the solution. I'll post more pics after a few more nights of testing. Fun stuff! Reply if you want me to blog more on the actual algorithms I'm using. I came up with a few interesting techniques for doing this.

Happy Coding!