Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (574) Games in Android Showcase (154) games submitted by our members Games in WIP (620) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Quick! Is there a Mathematician in the house?!  (Read 2363 times) 0 Members and 1 Guest are viewing this topic.
Dreamcatchermatt

Junior Devvie

 « Posted 2010-08-05 16:48:48 »

I've always wanted to say that...

This is slightly off topic, but still part of my Java project work, so I thought there might be someone here that can help me.

I'm working on a neural network project, and what i need to do is take the following sin wave (in black) and create the red line, which is the ideal output of the network.

Currently I've been doing this manually in Excel, because i have no idea how to calculate this. Basically, when the angle is at the 90 degree position, the output needs to be 1, and at the 270 degree position, it needs to be -1, and anywhere else it needs to be as close to zero as possible.

I probably wouldn't be the first to say I'm terrible with Trig'

Thanks all,
Matt

teletubo
« League of Dukes »

JGO Ninja

Medals: 60
Projects: 4
Exp: 8 years

 « Reply #1 - Posted 2010-08-05 16:54:57 »

cant you just write a function that does exactly what you described ?

 1  2  3  4  5  6  7  8  9  10  11  12 `/*** theta given in radians*/function myFunc(double theta){double sin = Math.sin(theta);if (sin==1 || sin==-1) return sin;return 0 ; }`

I have the felling I don't completely understand what you want, but anyway ...

Riven
« League of Dukes »

« JGO Overlord »

Medals: 953
Projects: 4
Exp: 16 years

 « Reply #2 - Posted 2010-08-05 16:58:42 »

Untested:
 1  2  3  4  5  6  7  8  9  10 `final float range = 15.0f;float degrees = ...; // anythingdegrees %= 360; // -359..359degrees += 360; // 1..719degrees %= 360; // 0..359if(isBetween(degrees,  90-range,  90+range))  return (range-Math.abs( 90-degrees)) / +range;if(isBetween(degrees, 270-range, 270+range))  return (range-Math.abs(270-degrees)) / -range;return 0.0f;`

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Riven
« League of Dukes »

« JGO Overlord »

Medals: 953
Projects: 4
Exp: 16 years

 « Reply #3 - Posted 2010-08-05 17:01:32 »

Alternatively, if you don't need the linear ramp:
 1  2  3 `double highNumber = 500; // seems to give good resultsdouble oddNumber = highNumber | 1; // otherwise you might end up without negative valuesMath.pow(Math.sin(angle), oddNumber);`

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Dreamcatchermatt

Junior Devvie

 « Reply #4 - Posted 2010-08-06 08:52:19 »

Alternatively, if you don't need the linear ramp:
 1  2  3 `double highNumber = 500; // seems to give good resultsdouble oddNumber = highNumber | 1; // otherwise you might end up without negative valuesMath.pow(Math.sin(angle), oddNumber);`

I think this is what I need.

I actually need to do this bit of code as an Excel formula rather than java code, to them save out as a CSV file and use with my program. I can sort that out though, its just the math that gets me

Thanks guys!

EDIT:
 1 `double oddNumber = highNumber | 1; // otherwise you might end up without negative values`

what does this line actually do? I've not come across inclusive OR before. (and I'm not getting any negative values)

EDITEDIT:

http://support.microsoft.com/kb/q132686/ Microsoft has no need for your primitive BODMAS! Blah!
Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

 « Reply #5 - Posted 2010-08-06 13:40:53 »

It will make sure the last bit is set.

ex.
101011011000 is OR'd with 0001 so it becomes 101011011001.

01101101 remains 01101101 because the last bit is already set.

See my work:
OTC Software
DzzD
 « Reply #6 - Posted 2010-08-06 16:33:41 »

Quote
what does this line actually do? I've not come across inclusive OR before. (and I'm not getting any negative values)

it return an odd number when input is even otherwise it return the same number

1 => 1
2 => 3
3 => 3
4 => 5
etc...

Dreamcatchermatt

Junior Devvie

 « Reply #7 - Posted 2010-08-06 18:24:06 »

Ahh, cool, that's actually a really useful thing to know
Cheers.

I did want to go down the Excel rout with this (for the graphing functions), but I may just write a program that dumps out the CSV's instead...

THis is getting further off topic, but has anyone found a really simple graphing package for java and swing? I cant remember which ones i've tried, but I've never found one that works, or is far too complicated and finiky to use for me to bother trying
teletubo
« League of Dukes »

JGO Ninja

Medals: 60
Projects: 4
Exp: 8 years

 « Reply #8 - Posted 2010-08-06 19:05:23 »

http://www.jfree.org/jfreechart/

I think this one is pretty straightforward, and it is very popular (i.e. there are a lot of faqs and tutorials).

Dreamcatchermatt

Junior Devvie

 « Reply #9 - Posted 2010-08-07 00:17:08 »

Hay, I got it working! Now I can get back to actual real programming

I feel really stupid asking this, but can anyone explain to me why raising to a power of an even number always returns a positive, and raising to the power of a odd number will do both positive and negative?

thanks for the graphing tip, I'm giving jFreeChart a go.
Riven
« League of Dukes »

« JGO Overlord »

Medals: 953
Projects: 4
Exp: 16 years

 « Reply #10 - Posted 2010-08-07 10:28:09 »

I feel really stupid asking this, but can anyone explain to me why raising to a power of an even number always returns a positive, and raising to the power of a odd number will do both positive and negative?

As you might remember from highschool:
+2*+2=+4
-2*+2=-4
+2*-2=-4
-2*-2=+4

In general:
[positive] * [positive] = [positive]
[positive] * [negative] = [negative]
[negative] * [negative] = [positive]

Let's write it out:
-2^1 =  -2    =  -2
-2^2 =  -2*-2 =  +4
-2^3 =  +4*-2 =  -8
-2^4 =  -8*-2 = +16
-2^5 = +16*-2 = -32
-2^6 = -32*-2 = +64

You can see that raising -2 to an odd number, the result is negative, and with an even number, the result is positive.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Riven (27 views) 2015-04-16 10:48:47 Duke0200 (42 views) 2015-04-16 01:59:01 Fairy Tailz (32 views) 2015-04-14 20:13:12 Riven (33 views) 2015-04-12 21:36:37 bus hotdog (49 views) 2015-04-10 02:39:32 CopyableCougar4 (51 views) 2015-04-10 00:51:04 BurntPizza (51 views) 2015-04-06 22:06:58 ags1 (53 views) 2015-04-02 10:58:48 Riven (52 views) 2015-04-01 18:27:05 ags1 (69 views) 2015-03-31 10:55:12
 theagentd 26x BurntPizza 18x wessles 15x 65K 11x kingroka123 11x Rayvolution 11x alwex 10x KevinWorkman 9x kevglass 8x phu004 8x Hanksha 7x SHC 7x ra4king 7x Olo 7x Roquen 7x chrislo27 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org