Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Quick! Is there a Mathematician in the house?!  (Read 2206 times)
0 Members and 1 Guest are viewing this topic.
Offline Dreamcatchermatt

Junior Member





« 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' Cheesy

Thanks all,
Matt

Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
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 ...

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 802
Projects: 4
Exp: 16 years


Hand over your head.


« 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 = ...; // anything
degrees %= 360; // -359..359
degrees += 360; // 1..719
degrees %= 360; // 0..359

if(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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 802
Projects: 4
Exp: 16 years


Hand over your head.


« 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 results
double oddNumber = highNumber | 1; // otherwise you might end up without negative values
Math.pow(Math.sin(angle), oddNumber);

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

Junior Member





« 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 results
double oddNumber = highNumber | 1; // otherwise you might end up without negative values
Math.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 Smiley

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!  Wink
Offline 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
Offline 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...

Offline Dreamcatchermatt

Junior Member





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

Ahh, cool, that's actually a really useful thing to know Cheesy
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 Wink
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
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).

Offline Dreamcatchermatt

Junior Member





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

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

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 802
Projects: 4
Exp: 16 years


Hand over your head.


« 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (34 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (51 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!