Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Tournicoti

Member Since 30 Aug 2009
Offline Last Active Today, 01:05 PM
**---

#5060158 [C#] Need help with Hopfield ANN

Posted by Tournicoti on 07 May 2013 - 06:57 PM

Not sure if you did this in your initialization, but in the weight matrix  :

 

Mat i,i=0

Mat i,j= Mat j,i

 

... is generally used : it permits to be sure the network will reach a stable state.

 

 

 

The capacity of a hopfield network is approximately nbPatterns=0.138*nbNodes, so 4 nodes is too small, maybe try with 10x10 nodes ( about 13 patterns in term of capacity )

 

I noticed you have implemented a synchronous method to compute the network state. It's totally possible even if initially, it was supposed to be asynchronous and stochastic.

 

Hope it can help !smile.png

 

If you still have problems with your implementation, I can post some pseudo-code if necessary




#5044314 Eight, Nine, Ten...

Posted by Tournicoti on 18 March 2013 - 12:55 PM

Obvious, the coder has 8 fingers on each hand




#5038864 funny idea for an ann game

Posted by Tournicoti on 03 March 2013 - 04:43 PM

I believe he wants to use an ANN for all of the game's logic.

 

I don't believe he understands the point (If any) of ANN's.

So what's the point (if any) of ANN ?




#5038486 video and ann

Posted by Tournicoti on 02 March 2013 - 01:12 PM

I don't know enought about this HTM model sorry, but a Mc Culloch & Pitts based neural model is a hyperplane. You can represent, visualize it as a plane in 3D, a line in 2D, in a visual application.




#5037832 MADE A SIMPLE NEURAL NETWORK, BUT NOT SURE IF I DID IT RIGHT

Posted by Tournicoti on 28 February 2013 - 06:56 PM

I would like to add another little thing :

 

What I described is the Perceptron as it was designed by Frank Rosenblatt (original version)

However there's another (very slightly different !) version in which -1 and 1 are used instead of 0 and 1 to encode booleans.

 

 

In term of learning efficiency it's better because  :

  • with 0 and 1, the weights will evolve only when deltaOutput is not zero and input is not zero.
  • with -1 and 1, the weights will always evolves when deltaOutput is not zero.

 

And this is 'nothing' to change :

  • change input encoding (so no more 0 and 1, but -1 and 1)
  • change the activation function :  sum>0.0f ? 1.0f : -1.0f

Bye smile.png




#5037171 MADE A SIMPLE NEURAL NETWORK, BUT NOT SURE IF I DID IT RIGHT

Posted by Tournicoti on 27 February 2013 - 08:52 AM

The learning rate is just an user-defined constant, here. It's usually a value between 0 and 1.

It's like defining the 'step' of the adaptation.

 

I would suggest to try low values first  (0.2 ? even less ?) because inputs[i]*deltaOutput is here a huge value : -1 or 0 or 1 !

 

Afterwards, the goal is to maximize the learning rate so that the learning process is quicker but still accurate enough for the wanted approximation.

 

Hope I'm still clear smile.png (sorry for my english, I'm getting tiredph34r.png )

 

Bye




#5037128 MADE A SIMPLE NEURAL NETWORK, BUT NOT SURE IF I DID IT RIGHT

Posted by Tournicoti on 27 February 2013 - 07:09 AM

Hello

This seems to be a good start for me smile.png

In fact you are precisely describing (wanting ?) Perceptron model

 

This is pseudo-code :

class Neuron
{
	float [] inputs; // (with : true is 1.0f, false is 0.0f)
	float [] weights;

	Constructor(integer nbInputs)
	{
		inputs=new array [nbInputs +1] (+1 is for including the bias). Or getting a reference on an external array.
		weights=new array [nbInputs +1]
		
		fill the weights array with float random values between -1 and 1
		set 1.0f in the position corresponding to the bias in the inputs array(typically, first or last position)
	}
	
	float computeOutput()
	{
		sum=dotProduct(inputs,weights);
		return sum>0.0f;
	}

	void learn(float desiredOutput,float learningRate) // adaptation of the weights
	{
		float output=computeOutput();
		float deltaOutput=desiredOutput-output; (so -1.0f or 0.0f or 1.0f)
		
		for each position in the arrays
		{
			weights[i]+=learningRate*inputs[i]*deltaOutput;
		}
	}

};

 

Hope it makes sense rolleyes.gif

 

for a OR, it should converge with : w1=w2=lambda, and wBias=0. With lambda>0

 

Good luck




#5036283 Finding a point inside a Pyramid

Posted by Tournicoti on 25 February 2013 - 03:19 AM

I add some code to help to see how it's possible to implement that :

	class PlaneD // a class that describes a plane, with a normal and a distance
	{
	public:
		D3DXVECTOR3 normal;
		float distance;


		PlaneD(D3DXVECTOR3 & n,D3DXVECTOR3 & p) // a constructor, given the normal and a point of the plane
			:normal(n)
			,distance(D3DXVec3Dot(&n,&p))
		{}
	};


	// ... and 2 functions I use to check if a point is 'behind' a plane :

	float computePointPlaneDistance(PlaneD & plane,D3DXVECTOR3 & point)
	{
		return D3DXVec3Dot(&plane.normal,&point)-plane.distance;
	}

	bool pointBehindPlane(D3DXVECTOR3 & point,PlaneD & plane)
	{
		return computePointPlaneDistance(plane,point)<=0.0f;
	}

As you can see I use D3DX API. You can just replace D3DXVECTOR3, D3DXVec3Dot with your own code.

Hope it helps smile.png

EDIT : Be sure to use normalized vector for the plane's normal, otherwise the calculations of the distances will be wrong.




#5036255 Finding a point inside a Pyramid

Posted by Tournicoti on 24 February 2013 - 09:49 PM

A pyramid is a convex volume, so if you can check your point against the 4 planes defining your pyramid, it's done ! smile.png

So, just compute the 4 planes equations and check if your point is 'below'(in term of half-spaces) all the planes.

Good luck




#5035410 Rotation of a Bounding Box around a point that is not the objects centre

Posted by Tournicoti on 22 February 2013 - 08:23 AM

It's possible to decompose this rotation around a fixed point into 3 transformations :

 

- first a translation, so that the fixed point becomes the origin

- then a 'standard' rotation (around the origin)

- then the inverse of the translation , to move back the box

 

Hope it can help ?




#4982654 Self-shadowing on curved shapes problem

Posted by Tournicoti on 22 September 2012 - 07:39 AM

Maybe should I be more specific about how it works ?

There are 2 maps of the same dimensions :
  • a depth map, like in standard shadow mapping
  • a color map, that stores the filtering colors
Generation of the shadow map :
  • the color map is filled with (1,1,1)
  • the opaque geometry is rendered on the depth map only
  • the transparent geometry is alpha-blended on the color map, reading the depth map.
Scene rendering with colored shadows :

The point is shadowed (depth test) ?
  • Yes, return (0,0,0)
  • No, sampling of the color map.
This filter is then multiplied by the light color, to get the filtered light color that can be used in lighting calculations afterwards


NB :
Since this shadow map stores the depth and the color filter of a light ray reaching an opaque geometry, it can be used on opaque geometry only.
I still use standard shadow mapping on transparent geometry, just taking into account the depth data of this shadow map.


Thank you so much for the help I got Posted Image


alwaysbetterthanblabla.PNG


#4982620 saturate()

Posted by Tournicoti on 22 September 2012 - 04:09 AM

Hello Posted Image

saturate(x) will clamp x between 0.0 and 1.0

saturate(-0.5) = 0.0
saturate(0.5)  = 0.5
saturate(1.5)  = 1.0
and so on

nb : x can be a scalar or even a vector ( or even a matrix). In this case, it operates on each component.


#4982232 Self-shadowing on curved shapes problem

Posted by Tournicoti on 20 September 2012 - 10:24 PM

Instead of using if statements while looping through split indices get the correct split index by adding up conditional statements for all the split tests. This does away with the need for branching.
...


thanks Posted Image


So here's my last version [EDITED] :

#define CSM_MAXSPLITS 8


SamplerState shadowMapSampler
{
	 Filter = MIN_MAG_MIP_POINT;
	 AddressU = BORDER;
	 AddressV = BORDER;
	 BorderCOLOR = float4(1.0f,1.0f,1.0f,1.0f);
};

float3 sampleColorCSM(in float posProjZ,in float3 posWorld,in float3 normalWorld)
{
	 float3 uv;
	 float bias;
	 uint split=0;
	 float4 posLight;

	 if (posProjZ<g_CSM_depths[0].x || posProjZ>g_CSM_depths[g_CSM_nbSplits].x) return float3(1.0,1.0f,1.0f);

	 [unroll (CSM_MAXSPLITS)]
	 for (uint i=1;i<=g_CSM_nbSplits;i++)
		  split+=posProjZ>g_CSM_depths[i].x;

	 posLight=mul(float4(posWorld,1.0f),g_CSM_VP[split]);
	 posLight/=posLight.w;

	 bias=dot(normalWorld,-g_vDirectionalLightDirection);
	 bias=clamp(g_CSM_depths[split].y*sqrt(1.0f-bias*bias)/bias,g_CSM_depths[split].y,g_CSM_depths[split].z);

	 uv=float3(posLight.xy*float2(0.5f,-0.5f)+0.5f,split);

	 return (g_CSMMaps.Sample(shadowMapSampler,uv).x+bias>posLight.z)*g_ColorCSMMaps.Sample(shadowMapSampler,uv).xyz;
}

float sampleCSM(in float posProjZ,in float3 posWorld,in float3 normalWorld)
{
	 float3 uv;
	 float bias;
	 uint split=0;
	 float4 posLight;

	 if (posProjZ<g_CSM_depths[0].x || posProjZ>g_CSM_depths[g_CSM_nbSplits].x) return 1.0f;

	 [unroll (CSM_MAXSPLITS)]
	 for (uint i=1;i<=g_CSM_nbSplits;i++)
		  split+=posProjZ>g_CSM_depths[i].x;

	 posLight=mul(float4(posWorld,1.0f),g_CSM_VP[split]);
	 posLight/=posLight.w;

	 bias=dot(normalWorld,-g_vDirectionalLightDirection);
	 bias=clamp(g_CSM_depths[split].y*sqrt(1.0f-bias*bias)/bias,g_CSM_depths[split].y,g_CSM_depths[split].z);

	 uv=float3(posLight.xy*float2(0.5f,-0.5f)+0.5f,split);

	 return g_CSMMaps.Sample(shadowMapSampler,uv).x+bias>posLight.z;
}

g_CSM_depths[split].x is the minimal depth of the #split map, g_CSM_depths[split+1].x is the maximal depth of the #split map.
g_CSM_depths[split].y is the minimal depth bias of the #split map  (remove acne on flat surfaces)
g_CSM_depths[split].z is the maximal depth bias of the #split map (remove acne on bumped surfaces)

Thanks for reading Posted Image


#4981993 Self-shadowing on curved shapes problem

Posted by Tournicoti on 20 September 2012 - 05:53 AM

Thanks, it solved the problem Posted Image

If you want to have a look on my HLSL colored csm sampling functions that use it :

#define CSM_MAXSPLITS 8

SamplerState shadowMapSampler
{
	Filter = MIN_MAG_MIP_POINT;
	AddressU = BORDER;
	AddressV = BORDER;
	BorderCOLOR = float4(1.0f,1.0f,1.0f,1.0f);
};

bool getSplitUV(in float posProjZ,in float3 posWorld,out uint split,out float2 uv,out float posLightZ)
{
split=1;
uv=0;
posLightZ=0;
[unroll (CSM_MAXSPLITS)]
for (;split<=g_CSM_nbSplits;split++)
  if (posProjZ<g_CSM_depths[split].x) break;

split--;
if (split==g_CSM_nbSplits) return false;

float4 posLight=mul(float4(posWorld,1.0f),g_CSM_VP[split]);
posLight/=posLight.w;
posLightZ=posLight.z;

uv=(posLight.xy)*float2(0.5f,-0.5f)+0.5f;

return true;
}

float3 sampleColorCSM(in float posProjZ,in float3 posWorld,in float3 normalWorld)
{
uint split;
float2 uv;
float posLightZ,factor;
if (getSplitUV(posProjZ,posWorld,split,uv,posLightZ))
{
  factor=saturate(dot(normalWorld,g_vDirectionalLightDirection));
  factor=saturate(sqrt(1.0f-factor*factor)/factor)*g_CSM_depths[split].y;
  factor=(g_CSMMaps.Sample(shadowMapSampler,float3(uv,split)).x+factor<posLightZ) ? 0.0f : 1.0f;
}
else
  factor=1.0f;
return factor*g_ColorCSMMaps.Sample(shadowMapSampler,float3(uv,split)).xyz;
}

PS :
g_CSM_depths[split].x is the minimal depth of the #split map, g_CSM_depths[split+1].x is the maximal depth of the #split map.
g_CSM_depths[split].y is the depth bias of the #split map
Any suggestion or improvement is welcome Posted Image


#4981612 Self-shadowing on curved shapes problem

Posted by Tournicoti on 19 September 2012 - 03:52 AM

Hello Posted Image

I have a problem of self-shadowing that I can't solve by changing the depth bias :
sm.PNG

I use (colored) cascaded shadow maps, each map has its own (constant) depth bias.

I wonder if there's a way to use partial derivatives (ddx ddy) to adjust the depth bias for each pixel ?

Thank you for any suggestion, or your help Posted Image

Nico




PARTNERS