Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
fritz
Jul 26, 2003

LP0 ON FIRE posted:

Sort of a math question, but in java script: I remember someone telling me before a few years ago how to make a simple oscillator function without using sine. I think it just uses addition and subtraction. Anyone know what this is?

You want a second order IIR filter http://www.ee.ic.ac.uk/pcheung/teaching/ee3_Study_Project/Sinewave%20Generation(708).pdf

Adbot
ADBOT LOVES YOU

fritz
Jul 26, 2003

Eela6 posted:

It's got to be the Taylor series , as mentioned. P.S: how do you think sin() is implemented under the hood?

With great difficulty:
https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/ieee754/dbl-64/s_sin.c;hb=HEAD#l281


(or as CORDIC if you're on fixed point)

Eela6
May 25, 2007
Shredded Hen
Well, I've got egg on my face.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Eela6 posted:

It's got to be the Taylor series , as mentioned. P.S: how do you think sin() is implemented under the hood?

Probably something similar to this. :v:

LP0 ON FIRE
Jan 25, 2006

beep boop

The Laplace Demon posted:

Check out the equations in the section titled "Block Behavior in Discrete Mode": https://www.mathworks.com/help/simulink/slref/sinewave.html

Yes! This is it. I also found it in some old code to make waves in water.

HappyHippo posted:

Why do you want this? If it's for "speed" I recommend sticking to sine unless you can prove that's what's slowing you down.

I didn't like the idea of a number continuously increasing and applying the math for sin on a larger and larger number.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



LP0 ON FIRE posted:

I didn't like the idea of a number continuously increasing and applying the math for sin on a larger and larger number.

So range clamp the number or use modulo if it bothers you?

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

LP0 ON FIRE posted:

I didn't like the idea of a number continuously increasing and applying the math for sin on a larger and larger number.

Just do x = x % (2 pi)

LP0 ON FIRE
Jan 25, 2006

beep boop

Munkeymon posted:

So range clamp the number or use modulo if it bothers you?

If you range clamp it, it's questionable what it should reset back to.

HappyHippo posted:

Just do x = x % (2 pi)

That's throwing in operations that are more expensive than a simple oscillator.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

LP0 ON FIRE posted:

If you range clamp it, it's questionable what it should reset back to.


That's throwing in operations that are more expensive than a simple oscillator.

If you're concerned about the runtime of the modulus operator, then I drat well hope your target platform is, like, a calculator. A TI-83+, maybe.

LP0 ON FIRE
Jan 25, 2006

beep boop

TooMuchAbstraction posted:

If you're concerned about the runtime of the modulus operator, then I drat well hope your target platform is, like, a calculator. A TI-83+, maybe.

It's not always the target platform, but also how much you are using it! ;)

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

LP0 ON FIRE posted:

It's not always the target platform, but also how much you are using it! ;)

Have you determined that in fact the computational cost of using library trig functions is imposing an unacceptable penalty on your performance?

In other words, are you prematurely optimizing?

(And if not, what the hell are you doing to a modern computer that you can't afford to call sin()? :stare:)

sarehu
Apr 20, 2007

(call/cc call/cc)
I'd like to point out that modulo by a fixed dividend can often be optimized by the compiler into something more efficient. I mean, you're using floating point, so uh... that ain't happening, but if it was some fixed point thing...?

Actually: x `fmod` y is just x - trunc(x * (1 / y)) * y

So yeah, you could imagine avoiding an actual division operation, and just using multiplication by constants 1 / (2pi) and 2pi.

Edit: And looking at some sources, some of them compute it with like, integer ops and stuff to avoid intermediate rounding error and I bet it's real slow.

sarehu fucked around with this message at 22:36 on Feb 2, 2017

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

LP0 ON FIRE posted:

It's not always the target platform, but also how much you are using it! ;)

Have you profiled your code and figured out that trig math is causing it to be slow, or are you just assuming?

LP0 ON FIRE
Jan 25, 2006

beep boop

Jabor posted:

Have you profiled your code and figured out that trig math is causing it to be slow, or are you just assuming?

I'm assuming based on something I already tried it with and got a performance boost, but this is lighter, and maybe it won't matter as much.

sarehu posted:

Actually: x `fmod` y is just x - trunc(x * (1 / y)) * y


The question there though is what is y, and if you had a lot of those as semi-large numbers, wouldn't you start taking a performance hit especially with the division?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

LP0 ON FIRE posted:

I'm assuming based on something I already tried it with and got a performance boost, but this is lighter, and maybe it won't matter as much.



The question there though is what is y, and if you had a lot of those as semi-large numbers, wouldn't you start taking a performance hit especially with the division?

Y is 2π, which is the point where trig functions have gone all the way around the circle and started repeating.

The trick with dividing by a constant is that you can actually calculate 1/y at compile-time, and so at runtime it's still just another multiplication.

LP0 ON FIRE
Jan 25, 2006

beep boop

Jabor posted:

Y is 2π, which is the point where trig functions have gone all the way around the circle and started repeating.

The trick with dividing by a constant is that you can actually calculate 1/y at compile-time, and so at runtime it's still just another multiplication.

That's true, except in the case where y is changing every time the function is called.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

LP0 ON FIRE posted:

That's true, except in the case where y is changing every time the function is called.

What are you actually trying to accomplish, because based on your comments either it's very weird or you're doing a poor job conveying what you want.

Like, what other values of Y could you possibly want to use, here, in the context of trig functions?

LP0 ON FIRE
Jan 25, 2006

beep boop
No I'm retarded and read your explanation wrong that y is 2π and can and 1/2π can just be calculated at compile time. :negative:

When I was making something in Obj-C that made 2d water waves in OpenGL, I stuck with using the simple osc because I got a performance increase, and now I want to revisit why. I want to recreate something like that in JS, and use sliders to edit the parameters and such. The original code uses a ton of points with spring physics, and you can throw objects into the water to have it react at a certain point to create stronger waves around the impact that dissipate.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
With JS I don't think your performance bottleneck is going to be sine vs. something else, but ultimately you have to test it to check.

Spring physics shouldn't require sine/cosine though? Hook's law just requires squaring.

sarehu
Apr 20, 2007

(call/cc call/cc)

HappyHippo posted:

Spring physics shouldn't require sine/cosine though? Hook's law just requires squaring.

Hooke's law :colbert:

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Damnit. And I have a physics degree too :(

LP0 ON FIRE
Jan 25, 2006

beep boop

HappyHippo posted:

With JS I don't think your performance bottleneck is going to be sine vs. something else, but ultimately you have to test it to check.

Spring physics shouldn't require sine/cosine though? Hook's law just requires squaring.

It does to make the water appear to be constantly moving. Kinda like the water in the New Super Bros Wii.

Blaziken386
Jun 27, 2013

I'm what the kids call: a big nerd
Hello, all. I'm kind of just starting out learning to code, and I'm currently working on a small project. Posting it in here because it's probably not too difficult if you know what you're doing (I don't, really) and so doesn't really need a thread of its own. That, and I don't really know what type of code would work best for it. HTML or Java, maybe?

Some background details: I'm trying to build a sort of search engine(?) for the Battle Network games. The series uses "battlechips" as the main game weapons, with 4-6 different versions of each battlechip that all have different values. (27 different possible values, one for each letter plus the asterisk.) IE - The chip Widesword can have the value of either C, E, L, Q, or Y; the chip Slasher can have the value of either B, D, G, R, or S; etc.

What I want is to be able to say, select "L" on a drop-down list, and have the program display every chip with the value of "L". I need to know how to assign multiple values (ie - Widesword:CELQY) to a single data entry, and how to make the code access a separate database of all those data entries and pull out the correct one.

In the end, I want to make it display something like this, listing every data entry meeting the criteria of "L".

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

You can do that kind of thing in any language and some things that you might not even call languages really!

So a better question is how do you want to use this? Is it going to be a website? Or a downloadable thing that runs on your computer? Who's going to use it? Are there any technologies you're interested in learning? HTML and JavaScript (I think you meant that instead of Java, you can use Java too though) would be a good choice for this kind of thing if you're into that - it's easy to get immediate results. Python is decent as an introduction to coding and working with data, but it's not as easy to get stuff looking pretty in a browser

But yeah really your options are wide open here, unless you have some specific requirements. Knowing what else you want it to eventually do might help as well, storing and retrieving data is sort of the basic stuff you can do with anything

e- oh yeah, just to give you an idea, you'd generally store your data (all the chips) somehow, including their letters, and then have some function that looks at them and pulls out the ones you want. That could be as simple as storing the letters as a string of characters, looking at each in turn to see if the chip you're looking at has the letter you're interested in, to fancier ways of structuring and filtering your data, to sticking it all in a proper database and running a simple query that pulls out exactly the records you want. Lots of ways to tackle the problem, if you start doing some tutorials for a language you'll start to get ideas of how to do it

baka kaba fucked around with this message at 11:01 on Feb 3, 2017

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
So, graph databases:

I know, they're beloved of data scientists and other non-programmers, but they're actually useful. We (a bunch of biologists) are using them to build interaction graphs of molecules (like many other bunches of biologists) to work out causation and interference. But there's so many graph implementations out there that it's ridiculous.

The most popular tool appears to be Neo4J, which in terms of getting a graph up and going is certainly the most straightforward and user-friendly. But:

- The scaling or distributed solutions are poor
- They really push you towards their query language, Cypher, rather than something more portable and programmable like Gremlin. (And I was having huge trouble with their official Python module, creating nodes in code that just never seemed to propagate to the actual db.)
- One graph per database, one database per server. If you want a second graph, make another server.
- I want to do some fairly sophisticated traversal and I'm finding it hard in Neo4J

Then there's the whole property graph versus triplet issue. I find the property approach more intuitive but lately triplets are seeming more logical.

So, what are people's favourite graph platforms? What issues should I look out for?

Squashy Nipples
Aug 18, 2007

I'm trying to scrape some web data. I trimmed the fat off the URLS, but I still don't understand the date formatting.
Anyone recognize this?

code:
11/30/16 Wednesday
[root URL]/ControlSales?date=583E5CD0

12/01/16 Thursday
[root URL]/ControlSales?date=583fd880

01/15/17 Sunday
[root URL]/ControlSales?date=587b2c00

01/16/17 Monday
[root URL]/ControlSales?date=587C5350

01/17/17 Tuesday
[root URL]/ControlSales?date=587dcf00

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Squashy Nipples posted:

I'm trying to scrape some web data. I trimmed the fat off the URLS, but I still don't understand the date formatting.
Anyone recognize this?

code:
11/30/16 Wednesday
[root URL]/ControlSales?date=583E5CD0

12/01/16 Thursday
[root URL]/ControlSales?date=583fd880

01/15/17 Sunday
[root URL]/ControlSales?date=587b2c00

01/16/17 Monday
[root URL]/ControlSales?date=587C5350

01/17/17 Tuesday
[root URL]/ControlSales?date=587dcf00

Hexadecimal encoding of a unix timestamp.

http://www.wolframalpha.com/input/?i=583E5CD0+base+16+to+base+10

https://unixtimestamp.org/1480482000

Squashy Nipples
Aug 18, 2007

Ok, Thanks!

It looked like hex, but I didn't understand the capitalization.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Squashy Nipples posted:

Ok, Thanks!

It looked like hex, but I didn't understand the capitalization.

My guess? Someone was sloppy with their hex generation code.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


outlier posted:

So, graph databases:

I know, they're beloved of data scientists and other non-programmers, but they're actually useful. We (a bunch of biologists) are using them to build interaction graphs of molecules (like many other bunches of biologists) to work out causation and interference. But there's so many graph implementations out there that it's ridiculous.

The most popular tool appears to be Neo4J, which in terms of getting a graph up and going is certainly the most straightforward and user-friendly. But:

- The scaling or distributed solutions are poor
- They really push you towards their query language, Cypher, rather than something more portable and programmable like Gremlin. (And I was having huge trouble with their official Python module, creating nodes in code that just never seemed to propagate to the actual db.)
- One graph per database, one database per server. If you want a second graph, make another server.
- I want to do some fairly sophisticated traversal and I'm finding it hard in Neo4J

Then there's the whole property graph versus triplet issue. I find the property approach more intuitive but lately triplets are seeming more logical.

So, what are people's favourite graph platforms? What issues should I look out for?

I've been looking at Cayley for a project I'm working on, but I'm constrained because it's for corporate use and we don't want to pay for a commercial license. There may be something better out there for academic purposes.

Squashy Nipples
Aug 18, 2007

carry on then posted:

My guess? Someone was sloppy with their hex generation code.

I had to fiddle with the date a bit, because the report is daily, and doesn't actually have a time, but I've got my function doing what I want now. :)

code:
Desired Date	Code Out	Date Back
11/30/2016	583F6800	11/30/2016
12/1/2016	5840B980	12/31/2016
1/15/2017	587C0D00	1/15/2017
1/16/2017	587D5E80	1/16/2017
1/17/2017	587EB000	1/17/2017
Thanks again!

Eela6
May 25, 2007
Shredded Hen

Blaziken386 posted:

Hello, all. I'm kind of just starting out learning to code, and I'm currently working on a small project. Posting it in here because it's probably not too difficult if you know what you're doing (I don't, really) and so doesn't really need a thread of its own. That, and I don't really know what type of code would work best for it. HTML or Java, maybe?

Some background details: I'm trying to build a sort of search engine(?) for the Battle Network games. The series uses "battlechips" as the main game weapons, with 4-6 different versions of each battlechip that all have different values. (27 different possible values, one for each letter plus the asterisk.) IE - The chip Widesword can have the value of either C, E, L, Q, or Y; the chip Slasher can have the value of either B, D, G, R, or S; etc.

What I want is to be able to say, select "L" on a drop-down list, and have the program display every chip with the value of "L". I need to know how to assign multiple values (ie - Widesword:CELQY) to a single data entry, and how to make the code access a separate database of all those data entries and pull out the correct one.

In the end, I want to make it display something like this, listing every data entry meeting the criteria of "L".


You can do this in pretty much any language. I would personally recommend Python 3 as a starter language, especially for something like this. Java is a language with a lot of boilerplate code that beginners often find frustrating. (Also, I just love Python.)

The Anaconda Distribution will give you everything you need to get up and running in Python. It even has a built-in IDE, Spyder, which I find to be excellent for beginner programmers. It makes it easy to see and correct your mistakes.

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

Squashy Nipples posted:

code:
12/1/2016	5840B980	12/31/2016

I hope this one is a typo, because otherwise it's a really weird bug.

Squashy Nipples
Aug 18, 2007

ulmont posted:

I hope this one is a typo, because otherwise it's a really weird bug.

Yep, fat finger. Hadn't built the scraper yet, was just pasting in URLs and looking.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



outlier posted:

So, graph databases:

I know, they're beloved of data scientists and other non-programmers, but they're actually useful. We (a bunch of biologists) are using them to build interaction graphs of molecules (like many other bunches of biologists) to work out causation and interference. But there's so many graph implementations out there that it's ridiculous.

The most popular tool appears to be Neo4J, which in terms of getting a graph up and going is certainly the most straightforward and user-friendly. But:

- The scaling or distributed solutions are poor
- They really push you towards their query language, Cypher, rather than something more portable and programmable like Gremlin. (And I was having huge trouble with their official Python module, creating nodes in code that just never seemed to propagate to the actual db.)
- One graph per database, one database per server. If you want a second graph, make another server.
- I want to do some fairly sophisticated traversal and I'm finding it hard in Neo4J

Then there's the whole property graph versus triplet issue. I find the property approach more intuitive but lately triplets are seeming more logical.

So, what are people's favourite graph platforms? What issues should I look out for?

A project I was on very briefly was using Titan for graph queries on supposedly big datasets. Titan is a distributed system for tinkerpop
graphs, which uses Gremlin and seems to be pretty capable of complex queries and support for many languages.

piratepilates fucked around with this message at 18:25 on Feb 3, 2017

Eela6
May 25, 2007
Shredded Hen

Blaziken386 posted:

Hello, all. I'm kind of just starting out learning to code, and I'm currently working on a small project. Posting it in here because it's probably not too difficult if you know what you're doing (I don't, really) and so doesn't really need a thread of its own. That, and I don't really know what type of code would work best for it. HTML or Java, maybe?

Some background details: I'm trying to build a sort of search engine(?) for the Battle Network games. The series uses "battlechips" as the main game weapons, with 4-6 different versions of each battlechip that all have different values. (27 different possible values, one for each letter plus the asterisk.) IE - The chip Widesword can have the value of either C, E, L, Q, or Y; the chip Slasher can have the value of either B, D, G, R, or S; etc.

What I want is to be able to say, select "L" on a drop-down list, and have the program display every chip with the value of "L". I need to know how to assign multiple values (ie - Widesword:CELQY) to a single data entry, and how to make the code access a separate database of all those data entries and pull out the correct one.

In the end, I want to make it display something like this, listing every data entry meeting the criteria of "L".


So to give you an example of where to start, I took this wiki page on battle network 2:

http://megaman.wikia.com/wiki/List_of_Mega_Man_Battle_Network_2_Battle_Chips
I scraped the data
http://pastebin.com/0T9E8R2s

I cleaned it up using this script
http://pastebin.com/EcW5maSC

and I outputted it to CSV
http://pastebin.com/eGEm36QA
(you might want to start here!)

There's also some other example code in there that might help you on your way.

I would try and work on your project in three steps.

1: Build your database of all the battle network games (probably by scraping and cleaning fan wikis)
2. Build a series of functions that give you the data you're looking for as text
3. Learn how to build a basic web-page and GUI that gives you access to that data (I recommend flask).

Anyways, if you don't end up using it, no big. I enjoyed this little project.

Eela6 fucked around with this message at 18:22 on Feb 3, 2017

redleader
Aug 18, 2005

Engage according to operational parameters

piratepilates posted:

tinkerpop, Gremlin

I'm trying to imagine having a serious conversation about adopting graph databases at work and having to use these words in a group of adults

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



redleader posted:

I'm trying to imagine having a serious conversation about adopting graph databases at work and having to use these words in a group of adults

You think just the names are bad? Take a look through the tinkerpop documentation first.

qntm
Jun 17, 2009

redleader posted:

I'm trying to imagine having a serious conversation about adopting graph databases at work and having to use these words in a group of adults

"Software with extremely stupid names" is a nearly endless trail of woe.

Adbot
ADBOT LOVES YOU

redleader
Aug 18, 2005

Engage according to operational parameters

piratepilates posted:

You think just the names are bad? Take a look through the tinkerpop documentation first.

Christ, you're not kidding.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply