text
stringlengths 0
27.6k
| python
int64 0
1
| DeepLearning or NLP
int64 0
1
| Other
int64 0
1
| Machine Learning
int64 0
1
| Mathematics
int64 0
1
| Trash
int64 0
1
|
---|---|---|---|---|---|---|
I hope someone could help me on this.
I want to add a month to a database date, but I want to prevent two jumping over month on those days at the end.
For instance I may have:
Jan 31 2009
And I want to get
Feb 28 2009
and not
March 2 2009
Next date would be
March 28 2009
Jun 28 2009
etc.
Is there a function that already perform this kind of operation in oracle?
EDIT
Yeap. I want to copy each month all the records with some status to the next ( so the user don't have to enter again 2,000 rows each month )
I can fetch all the records and update the date manually ( well in an imperative way ) but I would rather let the SQL do the job.
Something like:
insert into the_table
select f1,f2,f3, f_date + 30 /* sort of ... :S */ from the_Table where date > ?
But the problem comes with the last day.
Any idea before I have to code something like this?
for each record in
createObject( record )
object.date + date blabala
if( date > 29 and if februrary and the moon and the stars etc etc 9
end
update.... et
EDIT:2
Add months did the trick.
now I just have this:
insert into my_table
select f1, add_months( f2, 1 ) from my_table where status = etc etc
Thanks for the help.
| 0 | 0 | 0 | 0 | 1 | 0 |
Let's say I have 3 point clouds: first that has 3 points {x1,y1,z1}, {x2,y2,z2}, {x3,y3,z3} and second point cloud that has same points as {xx1, yy1, zz1}, {xx2,yy2,zz2}, {xx3,yy3,zz3}... I assume to align second point cloud to first I have to multiply second one's points by T[3x3matrix].
1) So how do I find this transform matrix(T) ? I tried to do the equations by hand, but failed to solve them. Is there an solution somewhere, cause I'm pretty sure I'm not the first one to stumble into the problem.
2) I assume that matrix might include skewing and shearing. Is there a way to find matrix with only 7 degrees of freedom (3translation, 3rotation, 1scale)?
| 0 | 0 | 0 | 0 | 1 | 0 |
When I pass the options in the program (a computational biology experiment) I usually pass them through a .py file.
So I have this .py file that reads like:
starting_length=9
starting_cell_size=1000
LengthofExperiments=5000000
Then I execute the file and get the data. Since the program is all on my machine and no one else has access to it, it is secure in a trivial way.
I can also write a similar file very easily:
def writeoptions(directory):
options=""
options+="starting_length=%s%s"%(starting_length,os.linesep)
options+="starting_cell_size=%s%s"%(starting_cell_size,os.linesep)
options+="LengthofExperiments=%s%s"%(LengthofExperiments,os.linesep)
...
open("%s%soptions.py"%(directory,os.sep),'w').write(options)
I want to pass a function as one of the parameters:
starting_length=9
starting_cell_size=1000
LengthofExperiments=5000000
def pippo(a,b):
return a+b
functionoperator=pippo
And of course in the real experiment the function pippo will be much more complex. And different from experiment to experiment.
But what I am unable to do is to write the function automatically. In short I don't know how to generalise the writeoptions function to keep on writing the options, if one of the options is a function. I could of course copy the original file, but this is inelegant, inefficient (because it contains a lot of extra options that are not being used), and generally does not solve the question.
How do you get python to write down the code of a function, as it writes down the value of a variable?
| 0 | 1 | 0 | 0 | 0 | 0 |
I am doing some float manipulation and end up with the following numbers:
-0.5
-0.4
-0.3000000000000000004
-0.2000000000000000004
-0.1000000000000000003
1.10E-16
0.1
0.2
0.30000000000000000004
0.4
0.5
The algorithm is the following:
var inc:Number = nextMultiple(min, stepSize);
trace(String(inc));
private function nextMultiple(x:Number, y:Number) {
return Math.ceil(x/y)*y;
}
I understand the fact the float cannot always be represented accurately in a byte. e.g 1/3. I also know my stepsize being 0.1. If I have the stepsize how could I get a proper output?
The strange thing is that its the first time I've encountered this type of problem.
Maybe I dont play with float enough.
| 0 | 0 | 0 | 0 | 1 | 0 |
TF-IDF (term frequency - inverse document frequency) is a staple of information retrieval. It's not a proper model though, and it seems to break down when new terms are introduced into the corpus. How do people handle it when queries or new documents have new terms, especially if they are high frequency. Under traditional cosine matching, those would have no impact on the total match.
| 0 | 1 | 0 | 0 | 0 | 0 |
I've become very addicted to Project Euler recently and am trying to do this one next! I've started some analysis on it and have reduced the problem down substantially already. Here's my working:
A = pqr and
1/A = 1/p + 1/q + 1/r so pqr/A =
pq + pr + qr
And because of the first equation:
pq+pr+qr = 1
Since exactly two of p, q and r have
to be negative, we can simplify the
equation down to finding:
abc for which ab = ac+bc+1
Solving for c we get:
ab-1 = (a+b)c
c = (ab-1)/(a+b)
This means we need to find a and b for
which:
ab = 1 (mod a+b)
And then our A value with those a and
b is:
A = abc = ab(ab-1)/(a+b)
Sorry if that's a lot of math! But now all we have to deal with is one condition and two equations. Now since I need to find the 150,000th smallest integer written as ab(ab-1)/(a+b) with ab = 1 (mod a+b), ideally I want to search (a, b) for which A is as small as possible.
For ease I assumed a < b and I have also noticed that gcd(a, b) = 1.
My first implementation is straight forward and even finds 150,000 solutions fast enough. However, it takes far too long to find the 150,000 smallest solutions. Here's the code anyway:
n = 150000
seen = set()
a = 3
while len(seen) < n:
for b in range(2, a):
if (a*b)%(a+b) != 1: continue
seen.add(a*b*(a*b-1)//(a+b))
print(len(seen), (a, b), a*b*(a*b-1)//(a+b))
a += 1
My next thought was to use Stern-Brocot trees but that is just too slow to find solutions. My final algorithm was to use the Chinese remainder theorem to check if different values of a+b yield solutions. That code is complicated and although faster, it isn't fast enough...
So I'm absolutely out of ideas! Anyone got any ideas?
| 0 | 0 | 0 | 0 | 1 | 0 |
I've got a classification problem in my hand, which I'd like to address with a machine learning algorithm ( Bayes, or Markovian probably, the question is independent on the classifier to be used). Given a number of training instances, I'm looking for a way to measure the performance of an implemented classificator, with taking data overfitting problem into account.
That is: given N[1..100] training samples, if I run the training algorithm on every one of the samples, and use this very same samples to measure fitness, it might stuck into a data overfitting problem -the classifier will know the exact answers for the training instances, without having much predictive power, rendering the fitness results useless.
An obvious solution would be seperating the hand-tagged samples into training, and test samples; and I'd like to learn about methods selecting the statistically significant samples for training.
White papers, book pointers, and PDFs much appreciated!
| 0 | 1 | 0 | 1 | 0 | 0 |
I'm looking at definitions of the A* path-finding algorithm, and it seems to be defined somewhat differently in different places.
The difference is in the action performed when going through the successors of a node, and finding that a successor is on the closed list.
One approach (suggested by Wikipedia, and this article) says: if the successor is on the closed list, just ignore it
Another approach (suggested here and here, for example) says: if the successor is on the closed list, examine its cost. If it's higher than the currently computed score, remove the item from the closed list for future examination.
I'm confused - which method is correct ? Intuitively, the first makes more sense to me, but I wonder about the difference in definition. Is one of the definitions wrong, or are they somehow isomorphic ?
| 0 | 1 | 0 | 0 | 0 | 0 |
I have a large (12 digit) BCD number, encoded in an array of 6 bytes - each nibble is one BCD digit. I need to multiply it by 10^x, where x can be positive or negative.
I know it can be done by shifting left or right by nibble instead of bit, but it's a horrible implementation - especially in Javacard, which is what I'm using. Is there a better way?
| 0 | 0 | 0 | 0 | 1 | 0 |
Should an API provide Rect::contains(Point) or Point::is_inside(Rect) or both?
or Math::contains(Point, Rect) cause it's symmetric?
The same Q goes for LineSegment::contains(Point), Rect::fully_contains(Circle) etc.
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm trying to do project Euler number 219 but am failing to get a grasp of it. I'm trying to use Python which according to project Euler should be able to do it within a minute! This leads me to think that they can't possibly want me to compute each individual bitstring since that would be too slow in Python - there has to be a sub O(n) algorithm.
I have looked at a recursive solution which stores the bitstrings possible prefixes so that it can quickly pick a new bitstring and it even considers them in groups. This only works in brute-forcing values up to a bit over 10:
cost(1) = 1
cost(2) = 5
cost(3) = 11
cost(4) = 18
cost(5) = 26
cost(6) = 35
cost(7) = 44
cost(8) = 54
cost(9) = 64
cost(10)= 74
cost(11)= 85
cost(12)= 96
Past this, I am struggling to comprehend how reduce the problem. It is always possible to make a pattern that goes like:
1
01
001
0001
00001
00000
But it isn't optimal for more than 7 bitstrings. Can anyone guide me in what I should be considering?
| 0 | 0 | 0 | 0 | 1 | 0 |
I have the following HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<style>
.box {
border: solid black 1px;
padding: 0px;
margin: 0px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<input class="box" style="width:300px;" /><br /><!--CRLF for clarity only-->
<input class="box" style="width:150px;" /><!--CRLF for clarity only-->
<input class="box" style="width:150px;" /><!--CRLF for clarity only-->
</form>
</body>
</html>
When rendered the 2nd row of textboxes appear to be cumulatively longer than the 1 on the first row. This despite explicit setting of widths via the style attribute
Why does this happen and can I avoid it?
Note: This appears to work the same in both FF3 and IE7
| 0 | 0 | 0 | 0 | 1 | 0 |
Have created a c++ implementation of the Hough transform for detecting lines in images. Found lines are represented using rho, theta, as described on wikipedia:
"The parameter r represents the distance between the line and the origin, while θ is the angle of the vector from the origin to this closest point "
How can i find the intersection point in x, y space for two lines described using r, θ?
For reference here are my current functions for converting in and out of hough space:
//get 'r' (length of a line from pole (corner, 0,0, distance from center) perpendicular to a line intersecting point x,y at a given angle) given the point and the angle (in radians)
inline float point2Hough(int x, int y, float theta) {
return((((float)x)*cosf(theta))+((float)y)*sinf(theta));
}
//get point y for a line at angle theta with a distance from the pole of r intersecting x? bad explanation! >_<
inline float hough2Point(int x, int r, float theta) {
float y;
if(theta!=0) {
y=(-cosf(theta)/sinf(theta))*x+((float)r/sinf(theta));
} else {
y=(float)r; //wth theta may == 0?!
}
return(y);
}
sorry in advance if this is something obvious..
| 0 | 0 | 0 | 0 | 1 | 0 |
I am doing some population modeling (for fun, mostly to play with the concepts of Carrying Capacity and the Logistics Function). The model works with multiple planets (about 100,000 of them, right now). When the population reaches carrying capacity on one planet, the inhabitants start branching out to nearby planets, and so on.
Problem: 100,000+ planets can house a LOT of people. More than a C# Decimal can handle. Since I'm doing averages and other stuff with these numbers, I need the capability to work with floating points (or I'd just use a BigInt library).
Does anyone know of a BigFloatingPoint class (or whatever) I can use? Google is being very unhelpful today. I could probably write a class that would work well enough, but I'd rather use something pre-existing, if such a thing exists.
| 0 | 0 | 0 | 0 | 1 | 0 |
My math classes are far behind, and I'm currently struggling to find a decent solution to a problem I'm having: I have a tree, in which nodes are actions, and are "weighted" according to multiple criteria : the cost of said action, the time it will take, the necessary resources, the disturbance, etc...
And I want to to find in this tree the path that minimizes both the cost AND the time for example, or the disturbance AND cost AND time, etc. My problem is that I have no idea on how to do it, except by coming up with a global cost function F(cost, time, resources,...), and apply a regular tree traversal algorithm using the result from F(...) as my only weight.
But then, how do I come up with F ? Something like "F(cost, time, resources) = a * cost + b * time + c * resources" feels very "unprofessional"...
Edit:
I wanted to avoid the word "summing" as I wasn't sure it was really the way to go, but in essence, that's what I'm doing: computing a total cost for each "path" or "branch" that goes from that top node, to one of the leafs, and choosing the "path" or "branch" that minimizes the cost. The problem being that each node has a weight based on the time necessary, on financial cost, on resource usage, etc.
So it seems inevitable to have to come up with a formula, as Stephan says, that will reduce all these parameters to one global cost, per node, which I can then sum across nodes as I travel down the tree, and pick the path that minimizes the total cost.
So I guess my question really is, it there a methodology to choose that function ?
Thanks for your answers and comments, it's starting to be a bit more clear in my head now.
| 0 | 0 | 0 | 0 | 1 | 0 |
We already have things like static analysis that tells us what's wrong with our code and where, so should we be endowing our IDEs with more AI features and, if so, which ones? I'm looking for ideas!
| 0 | 1 | 0 | 0 | 0 | 0 |
It could be part of the model because it's part of the business logic of the game.
It could be part of the controller because it could be seen as simulating player input, which would be considered part of the controller, right? Or would it?
What about a normal enemy, like a goomba in Mario?
UPDATE: Wow, that's really not the answer I was expecting. As far as I could tell, A.I. is an internal part of the autonomous game system, hence model. I'm still not convinced.
| 0 | 1 | 0 | 0 | 0 | 0 |
So maybe I want to have values between -1.0 and 1.0 as floats. It's clumsy having to write this and bolt it on top using extension methods IMO.
| 0 | 0 | 0 | 0 | 1 | 0 |
What is the best way to approximate a cubic Bezier curve? Ideally I would want a function y(x) which would give the exact y value for any given x, but this would involve solving a cubic equation for every x value, which is too slow for my needs, and there may be numerical stability issues as well with this approach.
Would this be a good solution?
| 0 | 0 | 0 | 0 | 1 | 0 |
What does the .NET framework provide, if anything, in the way of classes for performing geometric calculations? For example, calculating the distance between two points (represented as (x,y)) or solving a right triangle's unknown sides or internal angles? (I know that both of those are pretty easily solved; I'm just using those as examples).
If there's nothing built-in does anyone know of any open source or third party libraries that might be helpful?
| 0 | 0 | 0 | 0 | 1 | 0 |
I need your help,
For example I have a decimal type variable and I want to round up this way.
Eg
3.0 = 3
3.1 = 4
3.2 = 4
3.3 = 4
3.4 = 4
3.5 = 4
3.6 = 4
3.7 = 4
3.8 = 4
3.9 = 4
4.0 = 4
4.1 = 5
4.2 = 5
etc....
How can I do that?
| 0 | 0 | 0 | 0 | 1 | 0 |
Here's the basic scenario - I have a corpus of say 100,000 newspaper-like articles. Minimally they will all have a well-defined title, and some amount of body content.
What I want to do is find runs of text in articles that ought to link to other articles.
So, if article Foo has a run of text like "Students in 8th grade are being encouraged to read works by John-Paul Sartre" and article Bar is titled (and about) "The important works of John-Paul Sartre", I'd like to automagically create that HTML link from Foo to Bar within the text of Foo.
| 0 | 1 | 0 | 0 | 0 | 0 |
I'm trying to evaluate the purchase of a statistical tool. This will be used in part by non-programming users (doing clinical studies) and in part by programmers, so I'm trying to find a good compromise between usability and automation. Of course, cost is an issue, but if I can build a solid case, we could probably buy a commercial package, so we're not totally limited to free options.
So far, our options are:
Statistica (which some non-programmers already know)
Matlab Statistics toolbox (programmers already use matlab)
R language (would need a UI for non-programmers)
Hack something into Excel (not fun, but that's what non-programmers do right now)
?...
What else is out there? What's the industry standard? What kind of distinctive features should I look for? What would you recommend, and why?
Ideally, we'd like a tool that can run both on Linux and Windows machines.
(I work in medical imaging, so we do both biostatistics, and software engineering statistics)
| 0 | 0 | 0 | 0 | 1 | 0 |
if digit is the name for a number on base 10, what would be the name for a number on base 16? Hexgit?
| 0 | 0 | 0 | 0 | 1 | 0 |
We have several different optimization algorithms that produce a different result for each run. For example the goal of the optimization could be to find the minimum of a function, where 0 is the global minima. The optimization runs returns data like this:
[0.1, 0.1321, 0.0921, 0.012, 0.4]
Which is quite close to the global minima, so this is ok. Our first approach was to just choose a threshold, and let the unit test fail if a result occured that was too high. Unfortunately, this does not work at all: The results seem to have a gauss distribution, so, although unlikely, from time to time the test failed even when the algorithm is still fine and we just had bad luck.
So, how can I test this properly? I think quite a bit of statistics are needed here. It is also important that tests are still fast, just letting the test run a few 100 times and then take the average will be too slow.
Here are some further clarifications:
For example I have an algorithm that fits a Circle into a set of points. It is extremly fast but does not always produce the same result. I want to write a Unit test to guarantee that in most cases it is good enough.
Unfortunately I cannot choose a fixed seed for the random number generator, because I do not want to test if the algorithm produces the exact same result as before, but I want to test something like "With 90% certainty I get a result with 0.1 or better".
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm trying to learn a little more on vectormath through writing a simple ray tracer and I've been doing some reading on it, but what I haven't been able to find is how to determine the direction of the primary rays. This sounds like a simple problem and probably is, but with my current knowledge I haven't been able to figure it out.
I figured that I need a camera (nothing more than a location and a direction as vectors) and from the camera I fire the primary rays onto a screen in front of the camera which represents the final image. What I can't figure out are the corner coordinates of the screen. If I know the screen, finding the direction the primary rays is easy.
I'm hoping the screen can be figured out using nothing but simple math that doesn't require any rotation matrices. My best guess is this:
I have the direction of the camera as a vector, this direction is equal to the normal of the plane of the projection screen. So I have the normal of the screen, and from there I can easily calculate the center of the screen which is:
camera_location + (normal * distance)
Where distance is the distance between the screen and the camera. However, that's where I get lost and I can't find a way to figure out the corner coordinates of the plane for any arbitrary direction of the camera.
Can any of you help me out here? And if my method can't possibly work, what does?
| 0 | 0 | 0 | 0 | 1 | 0 |
Given I have a canvas that contains many shapes, lets say rectangles for now.
Each shape has a location (inches), size(inches) and rotation angle(degrees).
When a mouse click event happen inside the canvas for a location (x,y) in pixels.
I want to check if the clicked mouse position is inside/within a specific shape, considering the rotation angle and measurement unit conversion.
Can you help?
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm working on a Java applet that needs to display "fancy" equations. Is there any Java renderer for MathML or LaTeX that's open source? Ideally it would be a pure Java solution that doesn't use JNI.
Ideally it would also allow to animate the generated glyphs (e.g. animating adding a constant to both sides of a equation, lines going through terms for cancellation, etc.)
| 0 | 0 | 0 | 0 | 1 | 0 |
I need to write a function that takes 4 bytes as input, performs a reversible linear transformation on this, and returns it as 4 bytes.
But wait, there is more: it also has to be distributive, so changing one byte on the input should affect all 4 output bytes.
The issues:
if I use multiplication it won't be reversible after it is modded 255 via the storage as a byte (and its needs to stay as a byte)
if I use addition it can't be reversible and distributive
One solution:
I could create an array of bytes 256^4 long and fill it in, in a one to one mapping, this would work, but there are issues: this means I have to search a graph of size 256^8 due to having to search for free numbers for every value (should note distributivity should be sudo random based on a 64*64 array of byte). This solution also has the MINOR (lol) issue of needing 8GB of RAM, making this solution nonsense.
The domain of the input is the same as the domain of the output, every input has a unique output, in other words: a one to one mapping. As I noted on "one solution" this is very possible and I have used that method when a smaller domain (just 256) was in question. The fact is, as numbers get big that method becomes extraordinarily inefficient, the delta flaw was O(n^5) and omega was O(n^8) with similar crappiness in memory usage.
I was wondering if there was a clever way to do it. In a nutshell, it's a one to one mapping of domain (4 bytes or 256^4). Oh, and such simple things as N+1 can't be used, it has to be keyed off a 64*64 array of byte values that are sudo random but recreatable for reverse transformations.
| 0 | 0 | 0 | 0 | 1 | 0 |
This is actually a machine learning classification problem but I imagine there's a perfectly good quick-and-dirty way to do it. I want to map a string describing an NFL team, like "San Francisco" or "49ers" or "San Francisco 49ers" or "SF forty-niners", to a canonical name for the team. (There are 32 NFL teams so it really just means finding the nearest of 32 bins to put a given string in.)
The incoming strings are not actually totally arbitrary (they're from structured data sources like this: http://www.repole.com/sun4cast/stats/nfl2008lines.csv) so it's not really necessary to handle every crazy corner case like in the 49ers example above.
I should also add that in case anyone knows of a source of data containing both moneyline Vegas odds as well as actual game outcomes for the past few years of NFL games, that would obviate the need for this. The reason I need the canonicalization is to match up these two disparate data sets, one with odds and one with outcomes:
http://www.footballlocks.com/nfl_odds.shtml
http://www.repole.com/sun4cast/freepick.shtml
Ideas for better, more parsable, sources of data are very welcome!
Added: The substring matching idea might well suffice for this data; thanks! Could it be made a little more robust by picking the team name with the nearest levenshtein distance?
| 0 | 0 | 0 | 1 | 0 | 0 |
I am currently building a Neural Network library. I have constructed it as an object graph for simplicity. I am wondering if anyone can quantify the performance benefits of going to an array based approach. What I have now works very good for building networks of close to arbitrary complexity. Regular (backpropped) networks as well as recurrent networks are supported. I am considering having trained networks "compile" into some "simpler" form such as arrays.
I just wanted to see if anyone out there had any practical advice or experience building neural networks that deployed well into production. Is there any benefit to having the final product be array based instead of object graph based?
P.S Memory footprint is less important than speed.
| 0 | 0 | 0 | 1 | 0 | 0 |
I need your help in determining the best approach for analyzing industry-specific sentences (i.e. movie reviews) for "positive" vs "negative". I've seen libraries such as OpenNLP before, but it's too low-level - it just gives me the basic sentence composition; what I need is a higher-level structure:
- hopefully with wordlists
- hopefully trainable on my set of data
Thanks!
| 0 | 1 | 0 | 0 | 0 | 0 |
Homework question:
Cygwin GNU GDB
Cygwin GNU GCC
Attempting to establish the length of the hypotenuse C from the square root of A power of 2 and B power of 2.
Example input:
Enter the length of two sides of a right-angled triangle: 2.25 8.33
Answer:
The length of the hypotenuse is: 8.628523
Question: when I specify the same input as above, the result is not the same - output is 19.84.9596
Full code below:
float squareRoots(float *s)
{
float cx;
float nx;
float e;
cx = 1;
nx = (cx +*s/cx)/2;
e = nx - cx;
cx = nx;
if (e*e > 0.001)
{
nx = (cx +*s/cx)/2;
return nx;
} else {
return nx;
}
}
float hypotenuse(float *a, float *b)
{
float c;
//raise a to power of 2
*a = (*a * *a);
*b = (*b * *b);
//add a and b
float y = *a + *b;
c = squareRoots(&y);
return c;
}
int main()
{
float x,y;
printf("Enter the length of two sides of a right-angled triangle:");
scanf("%f %f", &x, &y);
float k=hypotenuse(&x,&y);
printf("The length of the hypotenuse is: %f", k);
exit(0);
}
| 0 | 0 | 0 | 0 | 1 | 0 |
From http://projecteuler.net/index.php?section=problems&id=99
Comparing two numbers written in index
form like 211 and
37 is not difficult, as any
calculator would confirm that
211 = 2048 37 =
2187.
However, confirming that
632382518061 >
519432525806 would be much
more difficult, as both numbers
contain over three million digits.
Using base_exp.txt (right click
and 'Save Link/Target As...'), a 22K
text file containing one thousand
lines with a base/exponent pair on
each line, determine which line number
has the greatest numerical value.
How might I approach this?
| 0 | 0 | 0 | 0 | 1 | 0 |
I have the following string (japanese) " ユーザー名" , the first character is "like" whitespace but its number in unicode is 12288, so if I do " ユーザー名".trim() I get the same string (trim doesn't work).
If i do trim in c++ it works ok.
Does anyone know how to solve this issue in java?
Is there a special trim method for unicode?
| 0 | 1 | 0 | 0 | 0 | 0 |
I have a set containing thousands of addresses. If I can get the longitude and latitude of each address, how do I split the set into groups by proximity?
Further, I may want to retry the 'clustering' according to different rules:
N groups
M addresses per group
maximum distance between any address in a group
| 0 | 0 | 0 | 1 | 0 | 0 |
I have a simple program, at it's heart is a two dimensional array of floats, supposedly representing gas concentrations, I have been trying to come up with a simple algorithm that will model the gas expanding outwards, like a cloud, eventually ending up with the same concentration of the gas everywhere across the grid.
For example a given state progression could be:
(using ints for simplicity)
starting state
00000
00000
00900
00000
00000
state after 1 pass of algorithm
00000
01110
01110
01110
00000
one more pas should give a 5x5 grid all containing the value 0.36 (9/25).
I've tried it out on paper but no matter how I try, I cant get my head around the algorithm to do this.
So my question is, how should I set about trying to code this algorithm? I've tried a few things, applying a convolution, trying to take each grid cell in turn and distributing it to its neighbours, but they all end up having undesirable effects, such as ending up eventually with less gas than I originally started with, or all of gas movement being in one direction instead of expanding outwards from the centre. I really can't get my head around it at all and would appreciate any help at all.
| 0 | 0 | 0 | 0 | 1 | 0 |
Does anyone know of a Java library that handles finding sentence boundaries? I'm thinking that it would be a smart StringTokenizer implementation that knows about all of the sentence terminators that languages can use.
Here's my experience with BreakIterator:
Using the example here:
I have the following Japanese:
今日はパソコンを買った。高性能のマックは早い!とても快適です。
In ascii, it looks like this:
\ufeff\u4eca\u65e5\u306f\u30d1\u30bd\u30b3\u30f3\u3092\u8cb7\u3063\u305f\u3002\u9ad8\u6027\u80fd\u306e\u30de\u30c3\u30af\u306f\u65e9\u3044\uff01\u3068\u3066\u3082\u5feb\u9069\u3067\u3059\u3002
Here's the part of that sample that I changed:
static void sentenceExamples() {
Locale currentLocale = new Locale ("ja","JP");
BreakIterator sentenceIterator =
BreakIterator.getSentenceInstance(currentLocale);
String someText = "今日はパソコンを買った。高性能のマックは早い!とても快適です。";
When I look at the Boundary indices, I see this:
0|13|24|32
But those indices don't correspond to any sentence terminators.
| 0 | 1 | 0 | 0 | 0 | 0 |
Trying to figure out an equation to get the current group a page would be in if they were grouped like below.
Variables:
PageSize = 5
PageIndex = 21
GroupSize = 5
TotalItems = 1000
CurrentPage = PageIndex + 1
Find:
**CurrentGroup = ?**
If there are 1000 items and you have a group size of 5 then there are 200 groups (TotalItems / GroupSize). This means that CurrentPage 22 must land in group 5
Group 1: 1 2 3 4 5
Group 2: 6 7 8 9 10
Group 3: 11 12 13 14 15
Group 4: 16 17 18 19 20
Group 5: 21 22 23 24 25
| 0 | 0 | 0 | 0 | 1 | 0 |
In Java, how do I round to an arbitrary value? Specifically, I want to round to .0025 steps, that is:
0.032611 -> 0.0325
0.034143 -> 0.0350
0.035233 -> 0.0350
0.037777 -> 0.0375
...
Any ideas or libs?
| 0 | 0 | 0 | 0 | 1 | 0 |
Im looking for an algorithm to be used in a racing game Im making. The map/level/track is randomly generated so I need to find two locations, start and goal, that makes use of the most of the map.
The algorithm is to work inside a two dimensional space
From each point, one can only traverse to the next point in four directions; up, down, left, right
Points can only be either blocked or nonblocked, only nonblocked points can be traversed
Regarding the calculation of distance, it should not be the "bird path" for a lack of a better word. The path between A and B should be longer if there is a wall (or other blocking area) between them.
Im unsure on where to start, comments are very welcome and proposed solutions are preferred in pseudo code.
Edit: Right. After looking through gs's code I gave it another shot. Instead of python, I this time wrote it in C++. But still, even after reading up on Dijkstras algorithm, the floodfill and Hosam Alys solution, I fail to spot any crucial difference. My code still works, but not as fast as you seem to be getting yours to run. Full source is on pastie. The only interesting lines (I guess) is the Dijkstra variant itself on lines 78-118.
But speed is not the main issue here. I would really appreciate the help if someone would be kind enough to point out the differences in the algorithms.
In Hosam Alys algorithm, is the only difference that he scans from the borders instead of every node?
In Dijkstras you keep track and overwrite the distance walked, but not in floodfill, but thats about it?
| 0 | 0 | 0 | 0 | 1 | 0 |
Convert angle in degrees to a point
How could I convert an angle (in degrees/radians) to a point (X,Y) a fixed distance away from a center-point.
Like a point rotating around a center-point.
Exactly the opposite of atan2 which computes the angle of the point y/x (in radians).
Note: I kept the original title because that's what people who do not understand will be searching by!
| 0 | 0 | 0 | 0 | 1 | 0 |
Does anyone have experience with algorithms for evaluating hypergeometric functions? I would be interested in general references, but I'll describe my particular problem in case someone has dealt with it.
My specific problem is evaluating a function of the form 3F2(a, b, 1; c, d; 1) where a, b, c, and d are all positive reals and c+d > a+b+1. There are many special cases that have a closed-form formula, but as far as I know there are no such formulas in general. The power series centered at zero converges at 1, but very slowly; the ratio of consecutive coefficients goes to 1 in the limit. Maybe something like Aitken acceleration would help?
| 0 | 0 | 0 | 0 | 1 | 0 |
I can't figure how get the integral & decimal value from a NSDecimalnumber.
For example, if I have 10,5, how get 10 & 5?
And if I have 10 & 5, how return to 10,5?
Mmm ok, that is looking better!
However I have the concer about lossing decimals.
This is for a app that will be international. If for example a user set the price "124,2356" I wanna load & save the exact number.
Mmm ok, that is the way, but not respect the # of decimal places. If exist a way to know that from the current local I'm set.
This is because that represent currency values...
| 0 | 0 | 0 | 0 | 1 | 0 |
I hear logarithms mentioned quite a lot in the programming context. They seem to be the solution to many problems and yet I can't seem to find a real-world way of making use of them. I've read the Wikipedia entry and that, quite frankly, leaves me none the wiser.
So, where can I learn about the real-world programming problems that logarithms solve? Has anyone got any examples of problems they faced that were solved by implementing a logarithm?
| 0 | 0 | 0 | 0 | 1 | 0 |
I was working for a telecom company some years ago and I had to generate a formula which calculates duration of a call according to the following algorithm:
t1 is the first period
t2 is the recurring period
RCT is the actual call time (in seconds)
CD is the effective call duration (for billing purposes)
if RCT is less than t1, then the CD equals t1
if RCT is greater than t1, then CD = t1 + x*t2, where x will "round" RCT to the next highest multiple of t2.
This algorithm translates to: "Charge for the first t1 seconds, then charge every t2 seconds after that".
Example:
t1 t2 RCT CD
60 10 48 60
60 10 65 70
60 10 121 130
30 20 25 30
30 20 35 50
30 20 65 70
Can you create a function / SQL that will return the "call duration" CD?
Without using if then else ...?
| 0 | 0 | 0 | 0 | 1 | 0 |
Ok, so - this is heavily related to my previous question Transforming an object between two coordinate spaces, but a lot more direct and it should have an obvious answer.
An objects local coordinate space, how do I "get a hold of it"? Say that I load an Orc into my game, how do I know programatically where it's head, left arm, right arm and origin (belly button?) is? And when I know where it is do I need to save it manually or is it something that magically exists in the DirectX API? In my other question one person said something about storing a vertice for X,Y,Z directions and and origin? How do I find these vertices? Do I pick them arbitrarily, assign them in the model before loading it into my game? etc.
This is not about transforming between coordinate spaces
| 0 | 0 | 0 | 0 | 1 | 0 |
In Perl, the % operator seems to assume integers. For instance:
sub foo {
my $n1 = shift;
my $n2 = shift;
print "perl's mod=" . $n1 % $n2, "
";
my $res = $n1 / $n2;
my $t = int($res);
print "my div=$t", "
";
$res = $res - $t;
$res = $res * $n2;
print "my mod=" . $res . "
";
}
foo( 3044.952963, 7.1 );
foo( 3044.952963, -7.1 );
foo( -3044.952963, 7.1 );
foo( -3044.952963, -7.1 );
gives
perl's mod=6
my div=428
my mod=6.15296300000033
perl's mod=-1
my div=-428
my mod=6.15296300000033
perl's mod=1
my div=-428
my mod=-6.15296300000033
perl's mod=-6
my div=428
my mod=-6.15296300000033
Now as you can see, I've come up with a "solution" already for calculating div and mod. However, what I don't understand is what effect the sign of each argument should have on the result. Wouldn't the div always be positive, being the number of times n2 fits into n1? How's the arithmetic supposed to work in this situation?
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm teaching a kid programming, and am introducing some basic artificial intelligence concepts at the moment. To begin with we're going to implement a tic-tac-toe game that searches the entire game tree and as such plays perfectly. Once we finish that I want to apply the same concepts to a game that has too many positions to evaluate every single one, so that we need to implement a heuristic to evaluate intermediate positions.
The best thing I could think of was Dots and Boxes. It has the advantage that I can set the board size arbitrarily large to stop him from searching the entire tree, and I can make a very basic scoring function be the number of my boxes minus the number of opponent boxes. Unfortunately this means that for most of the beginning of the game every position will be evaluated equivalently with a score of 0, because it takes quite a few moves before players actually start making boxes.
Does anyone have any better ideas for games? (Or a better scoring function for dots and boxes)?
| 0 | 1 | 0 | 0 | 0 | 0 |
So I'm reading the "3D Math Primer For Graphics And Game Development" book, coming from pretty much a non-math background I'm finally starting to grasp vector/matrix math - which is a relief.
But, yes there's always a but, I'm having trouble understand the translation of an object from one coordinate space to another. In the book the author takes an example with gun shooting at a car (image) that is turned 20 degrees (just a 2D space for simplicity) in "world space". So we have three spaces: World Space, Gun Object Space and Car Object Space - correct? The book then states this:
"In this figure, we have introduced a rifle that is firing a bullet at the car. As indicated by the
coordinate space on the left, we would normally begin by knowing about the gun and the trajectory
of the bullet in world space. Now, imagine transforming the coordinate space in line with the
car’s object space while keeping the car, the gun, and the trajectory of the bullet still. Now we
know the position of the gun and the trajectory of the bullet in the object space of the car, and we
could perform intersection tests to see if and where the bullet would hit the car."
And I follow this explanation, and when I beforehand know that the car is rotated 20* degrees in world space this isn't a problem - but how does this translate into a situation say when I have an archer in a game shooting from a hill down on someone else? I don't know the angle at which everything is displaced there?
And which object space is rotated here? The World or Gun space? Yeah as you can see I'm a bit confused.
I think the ideal response would be using the car and gun example using arbitrary variables for positions, angle, etc.
| 0 | 0 | 0 | 0 | 1 | 0 |
I am looking for a mathematical book on Lisp. Some ideas?
| 0 | 0 | 0 | 0 | 1 | 0 |
Mathematics naive question:
What is the "canonical" way to represent 14+1i?
14+i1
or
14+i
Similarly, is it likely, in the 'real world', that scientific notation is going to creep into a complex number so as to freak out a complex numbers parser? For example,
1.2345E+02-1.7002E-09i
Edit: Finally, is it
8.45358210351126e+066i
or
8.45358210351126e+66i
i.e. does one zero file to three digits on the imaginary?
| 0 | 0 | 0 | 0 | 1 | 0 |
a ticketing site offers a discount on "family" tickets.
a family ticket is 2 adults, 2 children.
the sell tickets page allows a user to enter any number of adult and child tickets.
How do I work out how to apply the family ticket discount, then charge all remaining tickets at their relevant cost (i.e. adult tickets cost more than child tickets) ?
Here's what I have so far (seems to work, but not 100% confident about it (php))
# Work out how many pairs of people there are
$numAdultPairs = floor($oForm->adult / 2);
$numChildPairs = floor($oForm->child / 2);
# work out the number of matching pairs for child / adult
if ( $numAdultPairs > $numChildPairs ) {
$numberOfFamilyTickets = $numAdultPairs - $numChildPairs;
} else if ( $numAdultPairs < $numChildPairs ){
$numberOfFamilyTickets = $numChildPairs - $numAdultPairs;
} else if ( $numAdultPairs == $numChildPairs ) {
$numberOfFamilyTickets = $numAdultPairs;
}
# work out the remaining tickets required
$remainingAdult = $oForm->adult % 2;
$remainingChild = $oForm->child % 2;
| 0 | 0 | 0 | 0 | 1 | 0 |
I have been trying to use a formula that is used to work out exclusive VAT in a program that our team is creating. The formula works correctly when used in a calculator or in excel, though gives a different output when used within a function in our program!
here is the function:
function fn_calcVat()
{
var vRate = Ext.getCmp('crd_vat_rate').getValue();
var vTranAmt = Ext.getCmp('crd_tran_amt').getValue();
if (vRate != '' && vTranAmt != '')
{
alert(Ext.getCmp('vatable').getValue().toString());
var vAmt = 0;
if (Ext.getCmp('vatable').getValue().toString() == 'Y')
{
vAmt = (vRate / ((vTranAmt / 100) + 1));
Ext.getCmp('crd_vat_amt').setValue(vAmt.toFixed(2));
Ext.getCmp('crd_tran_tot').setValue(vTranAmt.toString());
vAmt = 0;
}
else
{
vAmt = ((vRate / 100) * vTranAmt);
Ext.getCmp('crd_vat_amt').setValue(vAmt.toFixed(2));
Ext.getCmp('crd_tran_tot').setValue((vTranAmt + vAmt));
vAmt = 0;
}
}
}
the problem formula is vAmt = (vRate / ((vTranAmt / 100) + 1));
The other formula is working perfectly.
an example input would be 100 with a VAT rate of 14.00, and the expected answer would be a tax amount of 14, though it gives it as 7!!!
We are using a mashup of EXTJS, js and C#...
Any help would be greatly appreciated.
Kind Regards
Nick
| 0 | 0 | 0 | 0 | 1 | 0 |
There are two courses: "AI" and "AI in Games" both 15 students for 15 weeks.
I want to keep them motivated and creative.
I know I want some kind of competition (obvious for the latter course).
Maybe something like Marathon Match or ICFP.
I will need good visualization, so it would be great if it already exist.
One idea was to write AI for "Battle of Wesnoth", but I guess it's to diverse / boring.
Another game of Go. But that's too hard.
What are your ideas?
It will be work in groups of 3 students for 15 weeks.
| 0 | 1 | 0 | 0 | 0 | 0 |
So, it's been a few months since I wrote this question, since then I've toyed with "raw" C++ D3D, The Ogre and Irrlicht graphics engines and lately Microsoft XNA. I've built a few 2D games (mostly replicas of old stuff like tetris, astreoids, etc.) and made some (very) small steps into the 3D world in the above mentioned technologies.
I have little to no trouble creating the actual game logic, abstracting away object interactions to allow me to plug in different forms of control (computer, player, over network. etc.), doing threading or any of the other stuff I'm used to from my day to day work - which feels perfectly natural to me. I messed around very little with HLSL and particle effects (very very basic).
But 3D math involving Matrices and Vectors (and Quaternions(?) in Ogre3D, are these really needed?)... really gets me, I can follow examples (e.g. the Learning XNA 3.0 book I bought from O'Reilly, which is an awesome book btw) and I understand why and how something happens in the example, but when I try to do something myself I feel that I'm lacking the understanding of this type of math to be able to really get it and make it work by myself.
So I'm looking for resources on learning 3D math (mostly) and some Shader/Particle Effects books. I would prefer resources that are pedagogic and take it slow above something like a doctors thesis on vector math which will be way over my head. The ideal resource would be something that demonstrates it all in D3D.
| 0 | 0 | 0 | 0 | 1 | 0 |
I am wondering if anyone has any insight into this. I am thinking of going to grad school to get some computer science related degree. I have always been intrigued by people who are working on problems using statistical packages or simulation to solve problems. What would I study to get a good breadth of knowledge of these things? Do they fall into machine learning?
Thanks
| 0 | 0 | 0 | 1 | 0 | 0 |
As a fun side-project for myself to help in learning yet another PHP MVC framework, I've been writing Reversi / Othello as a PHP & Ajax application, mostly straightforward stuff. I decided against using a multidimensional array for a number of reasons and instead have a linear array ( in this case 64 elements long ) and a couple methods to convert from the coordinates to integers.
So I was curious, is there any other, possibly faster algorithms for converting an integer to a coordinate point?
function int2coord($i){
$x = (int)($i/8);
$y = $i - ($x*8);
return array($x, $y);
}
//Not a surprise but this is .003 MS slower on average
function int2coord_2($i){
$b = base_convert($i, 10, 8);
$x = (int) ($b != 0 ? $b/8 : 0); // could also be $b < 8 for condition
$y = $b % 10;
return array($x, $y);
}
And for posterity sake, the method I wrote for coord2int
function coord2int($x, $y){
return ($x*8)+$y;
}
Update:
So in the land of the weird, the results were not what I was expecting but using a pre-computed lookup table has predominantly shown to be the fastest, guess trading memory for speed is always a winner?
There was a table with times here but I cut it due to styling issues with SO.
| 0 | 0 | 0 | 0 | 1 | 0 |
I am extreamly interested in math and programming and planning to start symbolic math project from scratch.
Is this good project idea?
Where to start?
How should one approach this
project?
Any good resources?
Thanks in advance.
| 0 | 0 | 0 | 0 | 1 | 0 |
What I'm trying to do with MRS is to teach myself some basic AI; what I want to do is to make a rocket entity, with things such as vectored exhaust, and staging. Anyone have an idea on how to make an entity that can fly? Or do I just need to constantly apply a force upwards?
| 0 | 1 | 0 | 0 | 0 | 0 |
When training a multi-layer neural network, using a sigmoidal activation function is necessary for it to learn efficiently.
Is there any advantage to using a sigmoidal activation function when training a single layer perceptron, or is a simple step (heaviside) function sufficient (or even preferable)?
I'm slowly getting my head around neural networks but any help with this would be appreciated.
| 0 | 1 | 0 | 0 | 0 | 0 |
I am trying to write a simple AI for a "Get four" game.
The basic game principles are done, so I can throw in coins of different color, and they stack on each other and fill a 2D Array and so on and so forth.
until now this is what the method looks like:
public int insert(int x, int color) //0 = empty, 1=player1 2=player2"
X is the horizontal coordinate, as the y coordinate is determined by how many stones are in the array already, I think the idea is obvious.
Now the problem is I have to rate specific game situations, so find how many new pairs, triplets and possible 4 in a row I can get in a specific situation to then give each situation a specific value. With these values I can setup a "Game tree" to then decide which move would be best next (later on implementing Alpha-Beta-Pruning).
My current problem is that I can't think of an efficient way to implement a rating of the current game situation in a java method.
Any ideas would be greatly appreciated!
| 0 | 1 | 0 | 0 | 0 | 0 |
Update: I'm going to leave it as is: The performance hit of a exception (very rare) is better than the probably performance hit for checking on each operation (common)
I'm trying to support an "EstimatedRowCount" that in one case would be the product of two sub-cursors that are joined together:
estimatedRowCount = left.EstimatedRowCount * right.EstimatedRowCount;
return estimatedRowCount;
Of course, if left and right are big enough, this will throw an OverflowException.
Here, I don't really care if estimatedRowCount is 100% accurate, just big enough to know that this cursor is holding a lot of data.
Right now, I'm doing this:
// We multiply our rowcount
Int64 estimRowCount = 0;
try
{
estimRowCount = leftRowCount * rightRowCount;
}
catch (OverflowException)
{
// Ignore overflow exceptions
estimRowCount = Int64.MaxValue;
}
return estimRowCount;
Is there a better way to test for overflow operations so I don't have to do the try{}catch to guard?
| 0 | 0 | 0 | 0 | 1 | 0 |
I have a number of slots and pegs arranged in a straight line. The pegs can be moved and need to be moved to a slot each. A slot can be left empty only if all pegs are taken. When a peg is moved, it is not allowed to go past another peg. In other words the order of the pegs must be maintained. Preferably, the total distance moved by all pegs should be kept at a minimum. As far as possible, a peg should be placed in the nearest available slot.
All I want to know is: What field of mathematics deals with such a problem? What are the names of any well known algorithms which deal with similar problems? I am looking for Google fodder. Some keywords.
+--oooo-+--+---+---o--+------+--+-ooo+o-+-------o--+-----o-o-+-o
+ - Slots
o - Pegs
EDIT: I think that this visualization makes more sense. They are two separate tracks that need to line up.
Slots: +-------+--+---+------+------+--+----+--+----------+---------+--
Pegs: ---oooo------------o--------------ooo-o---------o--------o-o---o
EDIT: Just want to make it clear that the number of slots can be greater than, less than or equal to the number of pegs.
| 0 | 0 | 0 | 0 | 1 | 0 |
I want to shift away from Excel to Awk. I need basic mathematical operations, such as addition and division, for arrays.
For example, arrays A and B are [1, 3, 2] and [2, 1, 2], respectively. How can I get an array [2, 3, 4] from the multiplication between A and B? What about the addition and division between A and B?
| 0 | 0 | 0 | 0 | 1 | 0 |
What do you consider the most significant progress / breakthroughs in real world applications of present-day AI research? (including, but not limited to: machine learning, statistical data processing, and other disciplines spinned off from AI).
Please spare / do not want: ramblings about AI winters / disappointment;
Do want: links, and pointers to concrete real-world applications.
| 0 | 1 | 0 | 0 | 0 | 0 |
I have created a Python file to generate a Mandelbrot set image. The original maths code was not mine, so I do not understand it - I only heavily modified it to make it about 250x faster (Threads rule!).
Anyway, I was wondering how I could modify the maths part of the code to make it render one specific bit. Here is the maths part:
for y in xrange(size[1]):
coords = (uleft[0] + (x/size[0]) * (xwidth),uleft[1] - (y/size[1]) * (ywidth))
z = complex(coords[0],coords[1])
o = complex(0,0)
dotcolor = 0 # default, convergent
for trials in xrange(n):
if abs(o) <= 2.0:
o = o**2 + z
else:
dotcolor = trials
break # diverged
im.putpixel((x,y),dotcolor)
And the size definitions:
size1 = 500
size2 = 500
n=64
box=((-2,1.25),(0.5,-1.25))
plus = size[1]+size[0]
uleft = box[0]
lright = box[1]
xwidth = lright[0] - uleft[0]
ywidth = uleft[1] - lright[1]
what do I need to modify to make it render a certain section of the set?
| 0 | 0 | 0 | 0 | 1 | 0 |
I provided some of my programs with a feedback function. Unfortunately I forgot to include some sort of spam-protection - so users could send anything they wanted to my server - where every feedback is stored in a huge db.
In the beginning I periodically checked those feedbacks - I filtered out what was usable and deleted garbage. The problem is: I get 900 feedbacks per day. Only 4-5 are really useful, the other messages are mostly 2 type of gibberish:
nonsense: jfvgasdjkfahs kdlfjhasdf (People smashing their heads on the keyboard)
language i don't understand
What I did so far:
I installed a filter to delete any feedback containing "asdf", "qwer" etc... -> only 700 per day
I installed a word filter to delte anything containing bad language -> 600 per day (don't ask - but there are many strange people out there)
I filter out any messages containing letters not being used in my language -> 400 per day
But 400 per day is still way too much. So I'm wondering if anybody has dealt with such a problem before and knows some sort of algorithm to filter out senseless messages.
Any help would really be appreciated!
| 0 | 1 | 0 | 0 | 0 | 0 |
I am trying to animate an object, let's say its a car. I want it go from point
x1,y1,z1
to point x2,y2,z2 . It moves to those points, but it appears to be drifting rather than pointing in the direction of motion. So my question is: how can I solve this issue in my updateframe() event? Could you point me in the direction of some good resources?
Thanks.
| 0 | 0 | 0 | 0 | 1 | 0 |
Suppose you wanted to estimate the size of a userbase of a site which does not publicize this information.
People are more likely to have acquired different usernames with different probabilities. For instance, if the username 'nick' doesn't exist on the system, it's likely to have an extremely small userbase. If the username 'starbaby' is taken, it's likely to be a much larger site. It seems like a straightforward Bayesian problem.
There is the problem that different sites may have a different space of allowable usernames. The biggest problem would be the legality of common characters such as spaces, I imagine. Another issue that could taint the prior distribution is whether the site suggests names when the one you want is taken, or leaves you to think of a more creative name yourself.
How could you build a training set of the frequency of occurrence of usernames across different sized systems? Is there a way to use Bayes to do numeric estimation rather than classification into fixed-width buckets?
| 0 | 0 | 0 | 1 | 1 | 0 |
With reference to this programming game I am currently building.
I am using WPF to animate canvases, and I am using the BeginAnimation method to translate (move) a canvas across another canvas.
With the BeginAnimation, I need to specify the From and To coordinates for both x and y, and this is the method I am using this like such:
//X
Animator_Body_X.From = Translate_Body.X; //Current x-coordinate
Animator_Body_X.To = //The end X-coordinate
Translate_Body.BeginAnimation(TranslateTransform.XProperty, Animator_Body_X);
//Y
Animator_Body_Y.From = Translate_Body.Y; //Current y-coordinate
Animator_Body_Y.To = //The end Y-coordinate
Translate_Body.BeginAnimation(TranslateTransform.YProperty, Animator_Body_Y);
Now the canvas needs to be translated using a given angle, which I have available from the method.
So my question is, given the angle (0-359) the canvas is currently rotated at, starting x and y coordinates (of where the canvas is currently situated) and distance (in px), how do I calculate to end coordinates? ie to where the canvas will finally be translated to.
alt text http://img244.imageshack.us/img244/4794/canvastranspositionmi5.jpg
In the above image, I have drawn an example of what I want to achieve.
Suppose the canvas (solid-border box) has a current heading (angle) of 130 degrees, and it needs to be translated (following a path down that angle; ie depending on where it is currently facing) by 200 pixels...what will be the new coordinates (where it will stop animating: dashed-border box) of the canvas? How do I calculate these new coordinates of where it will stop?
[UPDATE] Solution:
Thanks to the help of both Andy and Cameron, it is finally working as intended.
And here is the working code:
double headingRadians = Heading * (Math.PI / 180);
Animator_Body_X.From = Translate_Body.X;
Animator_Body_X.To = Math.Sin(headingRadians) * pix + Translate_Body.X;
Translate_Body.BeginAnimation(TranslateTransform.XProperty, Animator_Body_X);
Animator_Body_Y.From = Translate_Body.Y;
Animator_Body_Y.To = ((Math.Cos(headingRadians) * pix) * -1) + Translate_Body.Y;
Translate_Body.BeginAnimation(TranslateTransform.YProperty, Animator_Body_Y);
| 0 | 0 | 0 | 0 | 1 | 0 |
I have a game world with lots of irregular objects with varying coordinate systems controlling how objects on their surface work. However the camera and these objects can leave and move out into open empty space, where a normal Cartesian coordinate system is used. How do I manage mapping between the two?
One idea I had would be to wrap these objects in a bounds such as a sphere or box, within which said coordinate system would be used, however this becomes problematic if those bounding objects overlap, at which point I'm unsure whether the idea is fundamentally flawed or a solution can be found, since these objects are moving and could overlap at some point
| 0 | 0 | 0 | 0 | 1 | 0 |
I have the current fov and the center pan and tilt values. How would I calculate what the pan and tilt values are of the edges(i.e. min pan value and max tilt) with this information?
| 0 | 0 | 0 | 0 | 1 | 0 |
I've been browsing Bjarne Stroustrup's new introductory programming book, Programming: Principles and Practice Using C++. It's meant for first-year university computer science and engineering students.
Early on in the book he works through an interesting extended example of creating a desktop calculator where he ends up implementing an arithmetic expression evaluator (that takes bracketed expressions and operator precedence into account) in a series of co-recursive functions based on a grammar.
This is a very interesting example, although arguably on the complex side for a lot of beginners.
I wonder what others thing of this particular example: would learning programming by seeing how to implement an expression parser excite and motivate you, or would it discourage you because of all the details and complexity?
Are there other good "real" programming examples for beginners?
| 0 | 0 | 0 | 0 | 1 | 0 |
When dealing with sparse matrices, how do I convert Matrix Market format into CRS (Compressed Row Storage)?
| 0 | 0 | 0 | 0 | 1 | 0 |
Problem: I have two overlapping 2D shapes, A and B, each shape having the same number of pixels, but differing in shape. Some portion of the shapes are overlapping, and there are some pieces of each that are not overlapping. My goal is to move all the non-overlapping pixels in shape A to the non-overlapping pixels in shape B. Since the number of pixels in each shape is the same, I should be able to find a 1-to-1 mapping of pixels. The restriction is that I want to find the mapping that minimizes the total distance traveled by all the pixels that moved.
Brute Force: The brute force approach to solving this problem is obviously out of the question, since I would have to compute the total distance of all possible mappings of which I think there are n! (where n is the number of non-overlapping pixels in one shape) times the computation of calculating a distance for each pair of points in the mapping, n, giving a total of O( n * n! ) or something similar.
Backtracking: The only "better" solution I could think of was to use backtracking, where I would keep track of the current minimum so far and at any point when I'm evaluating a certain mapping, if I reach or exceed that minimum, I move on to the next mapping. Even this won't do any better than O( n! ).
Is there any way to solve this problem with a reasonable complexity?
Also note that the "obvious" approach of simply mapping a point to it's closest matching neighbour does not always yield the optimum solution.
Simpler Approach?: As a secondary question, if a feasible solution doesn't exist, one possibility might be to partition each non-overlapping section into small regions, and map these regions, greatly reducing the number of mappings. To calculate the distance between two regions I would use the center of mass (average of the pixel locations in the region). However, this presents the problem of how I should go about doing the partitioning in order to get a near-optimal answer.
Any ideas are appreciated!!
| 0 | 0 | 0 | 0 | 1 | 0 |
With reference to this programming game I am currently building.
When the game is started, I am generating these robots at supposingly random points on a Canvas, and at first look (adding one or two bots at the same time), this seemed to be working as it should.
...but, when I added a ton of bots at the same time, this is how they where "randomly" appeared on the canvas:
alt text http://img22.imageshack.us/img22/6895/randombotpositionlf7.jpg
The supposedly random points don't seem that random after all...they're just points of a straight line!
Here is how I am calculating the Points:
SetStartingPoint(GetRandomPoint(ArenaWidth, ArenaHeight)); //the width and height are 550, 480 at the moment
//which calls:
private Point GetRandomPoint(double maxWidth, double maxHeight)
{
return new Point(new Random().Next(0, (int)(maxWidth-80)), new Random().Next(0, (int)maxHeight));
}
//and ultimately:
private void SetStartingPoint(Point p)
{
Translate_Body.X = (double)p.X;
Translate_Body.Y = (double)p.Y;
}
As regards the above code, Translate_Body is of type TranslateTransform of the robot (canvas), so by assigning its X and Y properties, it will change its position to the new values
What am I missing here?
[UPDATE] Solution:
The problem was like you all suggested, the numbers weren't being seeded properly because of the new instantiations.
I now changed the code to use a single Random variable and to seed all the points from it.
But I still can't understand why the points where being generated at a seemingly straight line of coordinates. Is anyone able to explain this ?
| 0 | 0 | 0 | 0 | 1 | 0 |
How would I solve:
-x^3 - x - 4 = 0
You can't use quadratic, because it is to the 3rd power, right?
I know I it should come out to ~1.3788 but I'm not sure how I would derive that.
I started with:
f(x) = x + (4/(x^2 + 1)).
Solving for 0, moving the x over to the other side, multiplying by (x^2 + 1) on both sides, I end up with:
-x(x^2 + 1) = 4,
or
-x^3 - x - 4 = 0.
| 0 | 0 | 0 | 0 | 1 | 0 |
With reference to this programming game I am currently building.
I wrote the below method to move (translate) a canvas to a specific distance and according to its current angle:
private void MoveBot(double pix, MoveDirection dir)
{
if (dir == MoveDirection.Forward)
{
Animator_Body_X.To = Math.Sin(HeadingRadians) * pix;
Animator_Body_Y.To = ((Math.Cos(HeadingRadians) * pix) * -1);
}
else
{
Animator_Body_X.To = ((Math.Sin(HeadingRadians) * pix) * -1);
Animator_Body_Y.To = Math.Cos(HeadingRadians) * pix;
}
Animator_Body_X.To += Translate_Body.X;
Animator_Body_Y.To += Translate_Body.Y;
Animator_Body_X.From = Translate_Body.X;
Translate_Body.BeginAnimation(TranslateTransform.XProperty, Animator_Body_X);
Animator_Body_Y.From = Translate_Body.Y;
Translate_Body.BeginAnimation(TranslateTransform.YProperty, Animator_Body_Y);
TriggerCallback();
}
One of the parameters it accepts is a number of pixels that should be covered when translating.
As regards the above code, Animator_Body_X and Animator_Body_Y are of type DoubleAnimation, which are then applied to the robot's TranslateTransform object: Translate_Body
The problem that I am facing is that the Robot (which is a canvas) is moving at a different speed according to the inputted distance. Thus, the longer the distance, the faster the robot moves! So to put you into perspective, if the inputted distance is 20, the robot moves fairly slow, but if the inputted distance is 800, it literally shoots off the screen.
I need to make this speed constant, irrelevant of the inputted distance.
I think I need to tweak some of the Animator_Body_X and Animator_Body_Y properties in according to the inputted distance, but I don't know what to tweak exactly (I think some Math has to be done as well).
Here is a list of the DoubleAnimation properties that maybe you will want to take a look at to figure this out.
| 0 | 0 | 0 | 0 | 1 | 0 |
I have 2 points, P and Q, on a directed line AB in 3D space. They can be anywhere on the line, i.e. not necessarily between A and B.
Pythagoras gives you the distance, obviously, but how do I calculate the sign of the directed distance from P to Q?
| 0 | 0 | 0 | 0 | 1 | 0 |
Let's say I have a small bitmap which contains a single digit (0..9) in hand writing.
Is it possible to detect the digit using a (two-layered) perceptron?
Are there other possibilities to detect single digits from bitmaps besides using neural nets?
| 0 | 1 | 0 | 0 | 0 | 0 |
Suppose I have this code
create temporary table somedata (a integer);
insert into somedata (a) values (11), (25), (62); --#these values are always increasing
select * from somedata;
giving this
+--+
|a |
+--+
|11|
|25|
|62|
+--+
How do I calculate a column of values 'b' where each one is the difference between the value of 'a' in the current row and the value of 'a' in the preceding row?
+--+--+
|a |b |
+--+--+
|11| 0| # ie 11-11 since theres no preceding row
|25|14| # ie 25-11
|62|37| # ie 62-25 etc
+--+--+
This is so obvious in openoffice or excel that I feel a bit silly not having yet found how to do this on MySql's site nor anywhere else.
| 0 | 0 | 0 | 0 | 1 | 0 |
What is the equation of a helix parametrized by arc length (i.e. a function of arc length) between any two points in space? Is there any function for this ? How do i implement the same using matlab or mathematica ?
| 0 | 0 | 0 | 0 | 1 | 0 |
I´m trying to break a number into an array of numbers (in php) in the way that for example:
25 becomes (16, 8, 1)
8 becomes (8)
11 becomes (8, 2, 1)
I don´t know what the correct term is, but I think the idea is clear.
My solution with a loop is pretty straightforward:
$number = rand(0, 128);
$number_array_loop = array();
$temp_number = $number;
while ($temp_number > 0) {
$found_number = pow(2, floor(log($temp_number, 2)));
$temp_number -= $found_number;
$number_array_loop[] = $found_number;
}
I also have a recursive solution but I can´t get that to work without using a global variable (don´t want that), the following comes close but results in arrays in arrays:
function get_numbers($rest_number) {
$found_number = pow(2, floor(log($rest_number, 2)));
if ($found_number > 0) {
$temp_array[] = get_numbers($rest_number - $found_number);
$temp_array[] = $found_number;
}
return $temp_array;
}
$number_array_recursive = array();
$number_array_recursive = get_numbers($number);
However, using something like pow(floor(log())) seems a bit much for a simple problem like this.
It seems to me that the problem calls for a recursive solution with some very simple maths, but I just don´t see it.
Any help would be apreciated.
Edit: Binary is the key, thanks a lot all!
| 0 | 0 | 0 | 0 | 1 | 0 |
How do I correct for floating point error in the following physical simulation:
Original point (x, y, z),
Desired point (x', y', z') after forces are applied.
Two triangles (A, B, C) and (B, C, D), who share edge BC
I am using this method for collision detection:
For each Triangle
If the original point is in front of the current triangle, and the desired point is behind the desired triangle:
Calculate the intersection point of the ray (original-desired) and the plane (triangle's normal).
If the intersection point is inside the triangle edges (!)
Respond to the collision.
End If
End If
Next Triangle
The problem I am having is that sometimes the point falls into the grey area of floating point math where it is so close to the line BC that it fails to collide with either triangle, even though technically it should always collide with one or the other since they share an edge. When this happens the point passes right between the two edge sharing triangles. I have marked one line of the code with (!) because I believe that's where I should be making a change.
One idea that works in very limited situations is to skip the edge testing. Effectively turning the triangles into planes. This only works when my meshes are convex hulls, but I plan to create convex shapes.
I am specifically using the dot product and triangle normals for all of my front-back testing.
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm working on a raytracer for a large side project, with the goal being to produce realistic renders without worrying about CPU time. Basically pre-rendering, so I'm going for accuracy over speed.
I'm having some trouble wrapping my head around some of the more advanced math going on in the lighting aspects of things. Basically, I have a point for my light. Assuming no distance falloff, I should be able to use the point on the polygon I've found, and compare the normal at that point to the angle of incidence on the light to figure out my illumination value. So given a point on a plane, the normal for that plane, and the point light, how would I go about figuring out that angle?
The reason I ask is that I can't seem to find any reference on finding the angle of incidence. I can find lots of references detailing what to do once you've got it, but nothing telling me how to get it in the first place. I imagine it's something simple, but I just can't logic it out.
Thanks
| 0 | 0 | 0 | 0 | 1 | 0 |
I want to find all the numbers divisble by all the numbers between 1 and 5. how do I write the program so that if the remainder of 'start' divided by all the numbers that x goes through is equal to 0 that it will print start. Is there any syntax that will calculate what I'm looking for. thanks.
import math
def main():
one = 1
start = 1
while one == 1:
for x in range(1, 5):
if start % x == 0:
print start
start += 1
| 0 | 0 | 0 | 0 | 1 | 0 |
SquareExp2 can be 9 or 16
Square can be 3 or 4
The Length of the gridbox and gridbox1 array can be 0 to 80 or 0 to 255
(you see the pattern now)
This code is ran only one time, at the start of the program.
For j = 0 To squareExp2 - 1
For i = 0 To squareExp2 - 1
box = (j * squareExp2) + i
gridbox(box) = ((j \ Square) * squareExp2 * Square) + ((j Mod Square) * Square) + (i \ Square) * squareExp2 + (i Mod Square)
gridbox1(gridbox(box)) = ((j \ Square) * squareExp2 * Square) + (((j Mod Square) * Square) * Square)
Next
Next
The goal of the code above is to move the code from
k = (gridRow(pos) \ iSquare) * iSquare
l = (gridCol(pos) \ iSquare) * iSquare
For i = l To l + iSquare - 1
For j = k To k + iSquare - 1
box = (j * squareExp2) + i
foundNumber(grid(box)) = grid(box)
Next
Next
to
j = myGridbox1(i)
For x = j To j + squareExp2 - 1
foundNumber(grid(myGridbox(x))) = grid(myGridbox(x))
Next
* edit *
in the end
Dim Square2 As Integer = iSquare * iSquare
Dim Square3 As Integer = Square2 * iSquare
Dim Square4 As Integer = Square2 * Square2
Dim j2_offset As Integer = 0
For j2 As Integer = 0 To iSquare - 1
Dim j1_offset As Integer = 0
Dim j1_interleaved_offset As Integer = 0
For j1 As Integer = 0 To iSquare - 1
Dim i2_offset As Integer = 0
Dim i2_interleaved_offset As Integer = 0
Dim j_offset_value As Integer = j2_offset + j1_offset
For i2 As Integer = 0 To iSquare - 1
Dim offset_value As Integer = j_offset_value + i2_offset
Dim interleaved_value As Integer = j2_offset + i2_interleaved_offset + j1_interleaved_offset
For i1 As Integer = 0 To iSquare - 1
box = offset_value + i1
gridbox(box) = interleaved_value + i1
gridbox1(gridbox(box)) = j_offset_value
Next
i2_offset += iSquare
i2_interleaved_offset += Square2
Next
j1_offset += Square2
j1_interleaved_offset += iSquare
Next
j2_offset += Square3
Next
Update
little followup, a few months later.
It was for a sudoku program and you can find where it being used here
| 0 | 0 | 0 | 0 | 1 | 0 |
Lets say I have guessed a lottery number of:
1689
And the way the lottery works is, the order of the digits don't matter as long as the digits match up 1:1 with the digits in the actual winning lottery number.
So, the number 1689 would be a winning lottery number with:
1896, 1698, 9816, etc..
As long as each digit in your guess was present in the target number, then you win the lottery.
Is there a mathematical way I can do this?
I've solved this problem with a O(N^2) looping checking each digit against each digit of the winning lottery number (separating them with modulus). Which is fine, it works but I want to know if there are any neat math tricks I can do.
For example, at first... I thought I could be tricky and just take the sum and product of each digit in both numbers and if they matched then you won.
^ Do you think that would work?
However, I quickly disproved this when I found that lottery guess: 222, and 124 have the different digits but the same product and sum.
Anyone know any math tricks I can use to quickly determine if the digits in num1 match the digits in num2 regardless of order?
| 0 | 0 | 0 | 0 | 1 | 0 |
What's the best algorithm for evaluating a mathematical expression? I'd like to be able to optimize this a little in the sense that I may have one formula with various variables, which I may need to evaluate hundreds of times using different variables. So basically if I can initially parse the formula so that it is optimized in some way, and I can then pass in the variables to this optimized version as many times as I need, each time it produces a result for me.
I'll be writing this in either Delphi or C#. I have already written something similar by using the shunting yard algorithm, but each time I need to calculate the same formula, I'm having to go through the parsing stage. There must be a better way to do this.
| 0 | 0 | 0 | 0 | 1 | 0 |
Given a few words of input, I want to have a utility that will return a diverse set of relevant terms, phrases, or concepts. A caveat is that it would need to have a large graph of terms to begin with, or else the feature would not be very useful.
For example, submitting "baseball" would return
["shortstop", "Babe Ruth", "foul ball", "steroids", ... ]
Google Sets is the best example I can find of this kind of feature, but I can't use it since they have no public API (and I wont go against their TOS). Also, single-word input doesn't garner a very diverse set of results. I'm looking for a solution that goes off on tangents.
The closest I've experimented with is using WikiPedia's API to search Categories and Backlinks, but there's no way to directly sort those results by "relevance" or "popularity". Without that, the suggestion list is massive and all over the place, which is not immediately useful and very hard to whittle down.
Using A Thesaurus could also work minimally, but that would leave out any proper nouns or tangentially relevant terms (like any of the results listed above).
I would happily reuse an open service, if one exists, but I haven't found anything sufficient.
I'm looking for either a way to implement this either in-house with a decently-populated starting set, or reuse a free service that offers this.
Have a solution? Thanks ahead of time!
UPDATE: Thank you for the incredibly dense & informative answers. I'll choose a winning answer in 6 to 12 months, when I'll hopefully understand what you've all suggested =)
| 0 | 1 | 0 | 0 | 0 | 0 |
It does not need to be very accurate. Does anyone know a good way to do this?
any help is much appreciated.
| 0 | 0 | 0 | 0 | 1 | 0 |
Is there a way to classify a particular sentence/paragraph as funny. There are very few pointers as to where one should go further on this.
| 0 | 1 | 0 | 0 | 0 | 0 |
I can't find anything other than closed-source web applications. Are there any active projects? I'd be interested in using the software in something I'm developing and getting involved.
| 0 | 1 | 0 | 0 | 0 | 0 |
Okay I'm trying to rotate a Java Polygon based on it's original position of angle 0. x, and y end up being converted to an int at the end of me using them, so I could understand not seeing some change, but when the difference in angles is big like 0 to 180 I think I should see something.
I've been at this for a little while and can't think of what it is. Here's the method. (Sorry if it messes up in the code tags, my firefox messes them up.)
public void rotate(double x, double y, obj o1)
{
double dist = Math.sqrt(Math.pow(x - (o1.x + (o1.w/2)), 2) + Math.pow(y - (o1.y + (o1.h/2)),2));
x += (Math.sin(Math.toRadians(o1.a)) * dist);
y -= (Math.cos(Math.toRadians(o1.a)) * dist);
}
| 0 | 0 | 0 | 0 | 1 | 0 |
Given two points say (1,2,3) and (4,7,8). The endpoint tangents at these points are also given as inputs say pi/4 and -pi/2 respectively. How to fit a helix of arc length 2 between these points?
How to implement this in Matlab?
| 0 | 0 | 0 | 0 | 1 | 0 |
I have various objects whose surfaces are 3D and non rectangular, such as spheres, pyramids, and various other objects represented by meshes. The mesh is not composed of polygons of equal size and distribution across the surface of the object, nor are they all semi/symmetrical objects like the ideal shapes of cylinders, spheres and cones.
Thus how would I go about engineering or retrofitting a pathfinding algorithm that took arbitrary meshes and generated nodes which could wrap around on themselves in any number of ways?
| 0 | 1 | 0 | 0 | 1 | 0 |
I have the following set of constraints in Perl (just a sample set of constraints, not the ones I really need):
$a < $b
$b > $c
$a is odd => $a in [10..18]
$a > 0
$c < 30
And I need to find a list ($a, $b, $c) that meet the constraints. My naive solution is
sub check_constraint {
my ($a, $b, $c) = @_;
if !($a < $b) {return 0;}
if !($b > $c) {return 0;}
if (($a % 2) && !(10 <= $a && $a <= 18)) {return 0;}
if !($a > 0) {return 0;}
if !($c < 30) {return 0;}
return 1;
}
sub gen_abc {
my $c = int rand 30;
my $b = int rand $c;
my $a = int rand $b;
return ($a, $b, $c);
}
($a, $b, $c) = &gen_abc();
while (!&check_constraint($a, $b, $c)) {
($a, $b, $c) = &gen_abc();
}
Now, this solution isn't guaranteed to end, and is pretty inefficient in general. Is there a better way to do this in Perl?
Edit: I need this for a random test generator, so the solution needs to use random functions such as rand(). A solution that's completely deterministic isn't enough, although if that solution can give me a list of possible combinations I can select an index at random:
@solutions = &find_allowed_combinations(); # solutions is an array of array references
$index = int rand($#solutions);
($a, $b, $c) = @$solution[$index];
Edit 2: The constraints here are simple to solve with brute force. However, if there are many variables with a large range of possible values, brute force isn't an option.
| 0 | 0 | 0 | 0 | 1 | 0 |
Simple question:
How do i tell which bits in the byte are set to 0 and which are set to 1
for example:
//That code would obviously wont work, but how do i make something similar that would work?
byte myByte = 0X32;
foreach(bool bit in myByte)
{
Console.WriteLine(bit);
}
//Part 2 revert
bool[] bits = new bool[8];
bits[0] = 0
bits[1] = 0
bits[2] = 0
bits[3] = 0
bits[4] = 0
bits[5] = 1
bits[6] = 0
bits[7] = 0
byte newByte = (byte)bits;
The entier internet is full of examples, but i just cant figure out
| 0 | 0 | 0 | 0 | 1 | 0 |
Okay, so I need to make C go the shortest path from A to B. A to B is the hypotenuse of my right triangle, and I need to give C the arctan of said triangle. How do I do this, and does the formula have a name?
| 0 | 0 | 0 | 0 | 1 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.