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'm implementing the system in this paper and I've come a little unstuck correctly implementing the radial tensor field. All tensors in this system are of the form given on page 3, section 4 R [ cos(2t), sin(2t); sin(2t), -cos(2t) ] The radial tensor field is defined as: R [ yy - xx, -2xy; -2xy, -(yy-xx) ] In my system I'm only storing R and Theta, since I can calculate the tensor based off just that information. This means I need to calculate R and Theta for the radial tensor. Unfortunately, my attempts at this have failed. Although it looks correct, my solution fails in the top left and bottom right quadrants. Addendum: Following on from discussion in the comments about the image of the system not working, I'll put some hard numbers here too. The entire tensor field is 800x480, the center point is at { 400, 240 }, and we're using the standard graphics coordinate system with a negative y axis (ie. origin in the top left). At { 400, 240 }, the tensor is R = 0, T = 0 At { 200, 120 }, the tensor is R = 2.95936E+9, T = 2.111216 At { 600, 120 }, the tensor is R = 2.95936E+9, T = 1.03037679 I can easily sample any more points which you think may help. The code I'm using to calculate values is: float x = i - center.X; float xSqr = x * x; float y = j - center.Y; float ySqr = y * y; float r = (float)Math.Pow(xSqr + ySqr, 2); float theta = (float)Math.Atan2((-2 * x * y), (ySqr - xSqr)) / 2; if (theta < 0) theta += MathHelper.Pi;
0
0
0
0
1
0
I have a given number of potential posts. We don't know how many there are but the system is set up to show 12 per page. Along the bottom I would like it to display the number of pages. So first if we get the posts: <?php $pages = get_posts('category_name=news'); ?> Now what we want to do is work out how many posts it has found divide that number by 12 round that number up to the nearest whole number (UP never down) divide that number by 1 and give how many times 1 goes into it. thus giving as many page numbers as needed. The ideas is to have them lined up as 1 | 2 | 3 | 4 | 5 etc.. Any ideas?
0
0
0
0
1
0
It's kind mathematics query..I want a script in php that will do following Let's say I've 100 pages page1.php, page2.php, page3.php, page4.php....goes on page100.php I want to create a php algorithm to link each page with one another. Each page will have 10 page links to other pages but I want a mathematical equation that will link each page. page1 will have 10 links to other pages, page2 will have 10 links to other pages, this will go on until each page is equally linked in total 100 pages with one another.
0
0
0
0
1
0
C#'s Math class does roots and powers in double only. Various things may go a bit faster if I add float-based square-root and power functions to my Math2 class (Today is a relaxation day and I find optimization relaxing). So - Fast square-root and power functions that I don't have to worry about licensing for, plskthx. Or a link that'll get me there.
0
0
0
0
1
0
I'm having some misunderstanding concerning Bayesian network. My main misunderstanding are independence and conditional independence!! If e.g. I have to calculate P(Burglary|Johncall), is it P(Burglary|Johncalls)=P(Burglary) because i'm seeing that Burglary is independent of Johncalls??
0
1
0
0
0
0
For a recent project I implemented the FP-Growth algorithm for reading in transactions and generating common sets, from which I then generate association rules. This is working well for my purposes. Now that I'm generating thousands of rules, I am looking for an efficient way to execute them... currently I'm storing the rules in a postgres table where the body is an array of integers and the head is a single int. My query looks for rows where the set of items I've got contains the body but not the head. I'm limited to using PHP and Postgres - this project is a small part of a much larger application. Could anyone recommend a data structure or table schema / direct me to some good resources? Also, what is the preferred term when discussing the application of association rules - evaluate, execute, lookup, run? Thanks!
0
1
0
0
0
0
Lets say I have: int a = textbox1; int b = textbox2; answer = a + b; How do you get "answer" to display in textbox3? I'm sure this is a very simple question, but believe it or not, I have done a lot of researching and found nothing. If you could please give an example as "Text" and as "numbers with decimals" I would greatly appreciate it!! Thank you in advance!
0
0
0
0
1
0
How can you add two fraction in c# like this: 11/6 + 3/4 = 31/12 and then how would you simplify the answer?
0
0
0
0
1
0
I'm trying with no luck to move a sprite position in an simetric curve way with the touch drag. So far I use the following code with no luck -(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event { lastTouchLocation = [MultiLayer locationFromTouch:touch]; return YES; } -(void) ccTouchMoved:(UITouch*)touch withEvent:(UIEvent *)event { CGPoint currentTouchLocation = [MultiLayer locationFromTouch:touch]; moveTo = ccpSub(lastTouchLocation, currentTouchLocation); lastTouchLocation = currentTouchLocation; } -(void) update:(ccTime)delta { CCSprite* sprite = [sprites objectAtIndex:1]; if (moveTo.x != 0){ float X = sprite.position.x + moveTo.x; float Y = sprite.position.y + (pow(X,2)); sprite.position = CGPointMake(X, Y); } } The curve way i'm trying to simulate is in the form y=x^2. Is this posible? Thanks in advance!
0
0
0
0
1
0
This is a homework question. I need to calculate 45^60 mod 61. I want to know of any fast method to get the result either programmatically or manually whichever is faster.
0
0
0
0
1
0
Here is my method so far: public static int[] simplifyRadical(int number) { int[] result = new int[2]; for (int i = 1; i < number / 2; i++) { if ((i % number == 0)) { //IS a factor of the number in the radical } } return result; } The format I'm using is result[0] = number outside radical and result[1] = number inside radical. So far, my method gets all the factors of number (which is the initial UNSIMPLFIED number in the radical). So how can I divide the initial number by the perfect square, get the square root of that and multiply that to my result[0] variable. Then keep looping until no perfect squares are found. I'm sorry if this question is confusing to read, it was definitely confusing to write. If you need any clarification, please comment below. UPDATE: So mathematically I am turning: sqrt(50) into 5 sqrt(2) because sqrt(50) = sqrt(25 * 2) and 25 is a perfect square of 5, thus: 5 sqrt(2) is formed.
0
0
0
0
1
0
S=solve(strcat('a*gamma(1+(1/b))=',int2str(m)),strcat('a*a*gamma(1+(2/b))=',int2str(c))); Values of variables m and c are known. How can one solve for a and b?
0
0
0
0
1
0
I'm trying to make an Euelr circle with a mehod that I wrote which uses class named Turtle. This is what I wrote: public class turtleAa { public static void main(String[] args) { int number = LineInput.readInt(); euelr(number); } public static void euelr(int n){ Turtle leonardo = new Turtle(); leonardo.tailDown(); for (int i=1; i<=n; i++){ leonardo.moveForward(50); leonardo.turnRight(90); leonardo.moveForward(50); leonardo.turnLeft(135); leonardo.moveForward(35); leonardo.turnLeft(90); leonardo.moveForward(35); leonardo.turnLeft(90); leonardo.moveForward(70.71067812); leonardo.turnLeft(135); leonardo.moveForward(50); leonardo.turnLeft(135); leonardo.moveForward(70.71067812); leonardo.turnLeft(135); leonardo.moveForward(50); leonardo.turnLeft(?) } }} I want to make a full circle of Euler drawnings Two main problems with this: Can't understad how to control correctly the angles with i and n. leonardo the turtle is drawing the lines. Thank you.
0
0
0
0
1
0
I have made game (Connect-4) and used MinMax algorithm with alpha-beta pruning for computer AI. What is good way to test correctness of my alpha-beta ? I am not sure of correctness, sometimes when playing against my AI it doesnt make the play that will make the game last longer if it has seen a loss deeper down and it is difficult to check things by hand and with unit testing when it starts searching just litle deep (7-9 moves). How can one fix this ? (I know if alpha beta might prune something that give more difficult win if there is no way not to lose)
0
1
0
0
0
0
I am putting together a project for a class that requires me to put AI in a top down Tactical Strategy game in Flash AS3. I decided that I would use a node based path finding approach because the game is based on a circular movement scheme. When a player moves a unit he essentially draws a series of line segments that connect that a player unit will follow along. I am trying to put together a similar operation for the AI units in our game by creating a list of nodes to traverse to a target node. Hence my use of Astar (the resulting path can be used to create this line). Here is my Algorithm function findShortestPath (startN:node, goalN:node) { var openSet:Array = new Array(); var closedSet:Array = new Array(); var pathFound:Boolean = false; startN.g_score = 0; startN.h_score = distFunction(startN,goalN); startN.f_score = startN.h_score; startN.fromNode = null; openSet.push (startN); var i:int = 0 for(i= 0; i< nodeArray.length; i++) { for(var j:int =0; j<nodeArray[0].length; j++) { if(!nodeArray[i][j].isPathable) { closedSet.push(nodeArray[i][j]); } } } while (openSet.length != 0) { var cNode:node = openSet.shift(); if (cNode == goalN) { resolvePath (cNode); return true; } closedSet.push (cNode); for (i= 0; i < cNode.dirArray.length; i++) { var neighborNode:node = cNode.nodeArray[cNode.dirArray[i]]; if (!(closedSet.indexOf(neighborNode) == -1)) { continue; } neighborNode.fromNode = cNode; var tenativeg_score:Number = cNode.gscore + distFunction(neighborNode.fromNode,neighborNode); if (openSet.indexOf(neighborNode) == -1) { neighborNode.g_score = neighborNode.fromNode.g_score + distFunction(neighborNode,cNode); if (cNode.dirArray[i] >= 4) { neighborNode.g_score -= 4; } neighborNode.h_score=distFunction(neighborNode,goalN); neighborNode.f_score=neighborNode.g_score+neighborNode.h_score; insertIntoPQ (neighborNode, openSet); //trace(" F Score of neighbor: " + neighborNode.f_score + " H score of Neighbor: " + neighborNode.h_score + " G_score or neighbor: " +neighborNode.g_score); } else if (tenativeg_score <= neighborNode.g_score) { neighborNode.fromNode=cNode; neighborNode.g_score=cNode.g_score+distFunction(neighborNode,cNode); if (cNode.dirArray[i]>=4) { neighborNode.g_score-=4; } neighborNode.f_score=neighborNode.g_score+neighborNode.h_score; openSet.splice (openSet.indexOf(neighborNode),1); //trace(" F Score of neighbor: " + neighborNode.f_score + " H score of Neighbor: " + neighborNode.h_score + " G_score or neighbor: " +neighborNode.g_score); insertIntoPQ (neighborNode, openSet); } } } trace ("fail"); return false; } Right now this function creates paths that are often not optimal or wholly inaccurate given the target and this generally happens when I have nodes that are not path able, and I am not quite sure what I am doing wrong right now. If someone could help me correct this I would appreciate it greatly. Some Notes My OpenSet is essentially a Priority Queue, so thats how I sort my nodes by cost. Here is that function function insertIntoPQ (iNode:node, pq:Array) { var inserted:Boolean=true; var iterater:int=0; while (inserted) { if (iterater==pq.length) { pq.push (iNode); inserted=false; } else if (pq[iterater].f_score >= iNode.f_score) { pq.splice (iterater,0,iNode); inserted=false; } ++iterater; } } Thanks!
0
1
0
0
0
0
There exist mathematical problem , it is the problem of generating sequence of n unique random numbers (random number is element of N { 0, ..., n }, ( like permutation, but without using memory ) Recentyl i kinda solved that problem, and I did get some result ( read bellow, without use of formal math, just by programming). and it seems that this problem is allready solved in past by constructing LFSR ( Linear feedback shift register ) by Galois or some other mathematician. ( i acctualy first found out of LFSR and than build my "kind of" soulution, because i couldn't understand LFSR article on wiki, and did't want to just copy paste the source code ) the thing is i don't understand a word of formal mathematics and would like to learn it and compare my solution with that of LFSR, so question is: can u compare what i did to that thing and somehow translate it to formal math and vice versa. so i can understand what i did and what formal mathematicians did ( and why they needed it )? remember my language is that of programming i only understand memory and its adressing, memory states, strings of zero and ones, etc. , and i don't understand primitive polynomials, field theory, and other math words. thank you very much in advance , if u can help me i will buy you a beer when i see you. here is my code bellow (u can run it in browser, i don't say it is correct but i belive idea should be close, i lack any other idea how to solve it. ): <html> <head> <script> //------------------------------------------------- function getPlacement( num ){ //; knuth permutations var places = []; for( var i = 0; i < num; ++i ) places.push( i ); var last_index = num-1; for( var i = num; i > 0; --i ){ var rnd_index = Random( i ); places = swap( places, rnd_index, last_index ); last_index--; } return places; } function readNum( num, placement ){ var numstr = num.toString(2); numstr = zeroextend( numstr, placement.length ); var numarr = numstr.split(''); var ret = []; for( var i = 0; i < placement.length; ++i ){ ret.push( numarr[ placement[i] ] ); } return ret.join(''); } function UniqRndSeq( maxLength, output ){ var placesNeeded = maxLength.toString(2).length; var randomPlacement = getPlacement( placesNeeded ); var initPosition = Random( maxLength ); var cnt = initPosition; var rndn; var numret = []; do{ rndn = parseInt( readNum( cnt, randomPlacement ), 2); output( rndn ); if( Containz( numret, rndn ) ) alert(rndn); numret.push(rndn); ++cnt; cnt = cnt % maxLength; } while( cnt != initPosition ); } //------------------------------------------------- //; helper funs var outp = []; function display( num ){ outp.push( num + "<br>" ); } function Random( x ){ return Math.floor(Math.random()*x); } function Containz( arr, num ){ for( var i = 0; i < arr.length; ++i ){ if( arr[i] == num ) return true; } return false; } function swap( list, a, b ){ var tmp = list[a]; list[a] = list[b]; list[b] = tmp; return list; } function zeroextend( num_bin_str, length ){ while( num_bin_str.length != length ){ num_bin_str = "0" + num_bin_str; } return num_bin_str; } //------------------------------------------------- function init(){ UniqRndSeq( 256, display); document.body.innerHTML = outp.join(''); } </script> </head> <body onload="init();"> </body> </html>
0
0
0
0
1
0
I have a Java program that does many calls to the Math.tanh() function. Out of curiosity I wanted to do a comparison with C++. Therefore I wrote two small programs, one in Java and one in C++, to test. The Java code: public class TestTanh { public static void main(String[] args) { double t1 = -1.0; double t2 = 1.0; double step = 1e-8; double z = 0.0; for(double t=t1; t<=t2; t += step) { double y = Math.tanh(t); z += y; } System.out.println("Sum = " + z); } } and the C++ code: #include <iostream> #include <cmath> using namespace std; int main() { double t1 = -1.0; double t2 = 1.0; double step = 1e-8; double z = 0.0; for(double t=t1; t<=t2; t += step) { double y = tanh(t); z += y; } cout << "Sum = " << z << " "; } Compiling and running the programs I got the following: $ time java TestTanh Sum = -0.41281032759865655 real 0m18.372s user 0m17.961s sys 0m0.109s and $ time ./test_tanh Sum = -0.41281 real 0m4.022s user 0m3.641s sys 0m0.004s Why does the Java program take about 5 times more time to execute? Could it be related to the JIT doing some compiling first? Or is the tanh implementation in Java slower than the C++? It is a simple test that might have a trivial explanation but I have searched the web and not found an answer. My Java version is $ java -version java version "1.6.0_22" Java(TM) SE Runtime Environment (build 1.6.0_22-b04-307-10M3261) Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03-307, mixed mode) When using the tanh function in a larger program containing other basic arithmetic operations the difference between Java and C++ became smaller (now about 2.3). The program still calls tanh repeatedly, but now there are also other operations in the loop. I also tried the FastMath class from Apache Commons, but is was actually slower (any special settings needed?). The result for this program with identical parameters were: C++ real 0m18.031s user 0m18.007s sys 0m0.007s Java with lang.Math real 0m40.739s user 0m40.032s sys 0m0.088s Java with org.apache.commons.math.util.FastMath real 0m46.717s user 0m46.583s sys 0m0.372s My goal here was not to do any true benchmarking, I just wanted to see what the differences were in a practical situation when implementing the code in a straightforward way.
0
0
0
0
1
0
I'm implementing the system detailed in this paper. On page 3, section 4 it shows the form that tensors take within the system: R [ cos(2t), sin(2t); sin(2t), -cos(2t) ] In my system, I only store R and t, since everything can be calculated from them. However, I've got to the point where I need to sum two of these tensors (page 4, section 5.2). How can I find values for R and t after summing two tensors of this form?
0
0
0
0
1
0
I'm trying to translate latitude and longitude coordinates into coordinates of my own defined map. For instance: 51.876324 maps to 659.33 in my map 0.943395 maps to 2585.17 in my map other such examples might be: 51.875737 - 505.77 0.943564 - 2055.39 51.875883 - 1090.58 0.944658 - 1935.42 My math skills/knowledge is kind of rusted, but should I use substitution to find out what is the factor by which the coordinates can be mapped into mine? Any hints are appreciated Cheers!
0
0
0
0
1
0
If I have a mesh of triangles, how does one go about calculating the normals at each given vertex? I understand how to find the normal of a single triangle. If I have triangles sharing vertices, I can partially find the answer by finding each triangle's respective normal, normalizing it, adding it to the total, and then normalizing the end result. However, this obviously does not take into account proper weighting of each normal (many tiny triangles can throw off the answer when linked with a large triangle, for example).
0
0
0
0
1
0
If I have three points A, B, C and I know the distances between them and A is at 2D coordinates {0,0} and B is at {ab,0}, then what would be the formula to find the coordinates of the point C?
0
0
0
0
1
0
Lets say I have an angle... what would be a reasonable way to go about finding the next point of where the ball would be? Variables: bSpeed, bAngle, Ball.x, Ball.y You knwon when you do c^2 = a^2 + b^2... is there a way you could find how long c^2 could be and actually "draw" it out and then use speed to go only part of that... with that find a^2 and b^2 so you can actually have a x and a y to draw the ball... Thanks ahead of time! (BTW, I don't need code... just reasoning and wisdom)
0
0
0
0
1
0
I am having a problem here it crashes when I have 2 moles, but if there is just one it doesnt crash. private int randX(){ int x = (int) Math.round((Math.random()*CollierSurface.getWidth())); if (x<CollierSurface.getWidth()) randX(); return x; } private int randY(){ int y = (int) Math.round((Math.random()*CollierSurface.getHeight())); if (y<CollierSurface.getWidth()) randY(); return y; } private void DrawMoles() { if (!_canDraw) return; try { CollierCanvas = CollierHolder.lockCanvas(); Drawable background = getResources().getDrawable(R.drawable.collierabove); background.setBounds(0, 0, CollierSurface.getWidth(), CollierSurface.getHeight()); background.draw(CollierCanvas); newMole(randX(), randY(), mole1); newMole(randX(), randY(), mole2); } catch (SurfaceHolder.BadSurfaceTypeException e) { } finally { if (CollierCanvas != null){ CollierHolder.unlockCanvasAndPost(CollierCanvas); } } } private void newMole(int x, int y, Drawable mole){ mole = getResources().getDrawable(R.drawable.mole); mole.mutate().setBounds((int)x-(mole.getIntrinsicWidth()), (int)y-(mole.getIntrinsicHeight()), (int)x+(mole.getIntrinsicWidth()), (int)y+(mole.getIntrinsicHeight())); mole.draw(CollierCanvas); } Log cat of crash 03-19 17:48:14.342: ERROR/Setting(1969): USB debugging enabled 03-19 17:48:18.462: WARN/PowerManagerService(1928): Timer 0x3->0x3|0x1 03-19 17:48:18.777: ERROR/AndroidRuntime(10073): ERROR: thread attach failed 03-19 17:48:19.802: ERROR/AndroidRuntime(10081): ERROR: thread attach failed 03-19 17:48:19.927: WARN/Resources(1928): Converting to boolean: TypedValue{t=0x3/d=0xc4e "res/anim/accelerate_decelerate_interpolator.xml" a=2 r=0x10a0004} 03-19 17:48:19.947: WARN/Resources(1928): Converting to boolean: TypedValue{t=0x3/d=0xc4e "res/anim/accelerate_decelerate_interpolator.xml" a=2 r=0x10a0004} 03-19 17:48:19.962: WARN/ActivityThread(10088): Application com.collierhs.game is waiting for the debugger on port 8100... 03-19 17:48:22.647: ERROR/gralloc(1928): [unregister] handle 0x454ea0 still locked (state=40000001) 03-19 17:48:24.237: WARN/dalvikvm(10094): No implementation found for native Lcom/carrieriq/iqagent/client/NativeClient;.clientInit (Ljava/lang/Object;)I 03-19 17:48:39.750: WARN/ActivityManager(1928): Launch timeout has expired, giving up wake lock! 03-19 17:48:39.922: WARN/ActivityManager(1928): Activity idle timeout for HistoryRecord{4597c840 com.collierhs.game/.whack}
0
0
0
0
1
0
How might I create a C# program to decide how, say, sad a person is? Do you think it might work just to pick out "depressed" words, or would that not go far enough? I could use a neural network if needed. UPDATE: Assuming that we know the prompt that the user is referring to, and that we know how that prompt should be responded to. We also have other sentences that they have marked as "happy", "sad" etc. Yes, they are in front of a webcam with a mic. Sorry if the question is too vague.
0
1
0
0
0
0
I have two classes of data which are plotted in 2D and I wish to plot the nearest-neighbours decision boundary for a given value of k. I realise that there is a similar example provided in Matlab's 'classify' help doc, however I do not see how I can use this within the context of k nearest-neighbours. Thanks, Josh
0
0
0
1
0
0
The I in PID (Proportional Integral Derivative) is the sum of the last few previous errors, weighted only by it's gain. Using error(-1) to mean the previous error, error(-2) to mean the error before that etc... 'I' can be described as: I = (error(-1) + error(-2) + error(-3) + error(-4) etc...) * I_gain Why when PID was designed was 'I' not instead designed to slope off in importance into the past, for example: I = (error(-1) + (error(-2) * 0.9) + (error(-3) * 0.81) + (error(-4) * 0.729) + etc...) * I_gain edit: reworded
0
0
0
0
1
0
Do you know what is this, and How they represent decisions (using probabilities) in Decision Theory Are they similar to decision trees?
0
1
0
0
0
0
I am reviewing this MATLAB code,and it have some examples, I am executing test_bnpc_asia.m, but get an error, How to correct it? (I have MATLAB R2010B) executing: >> test_bnpc_asia.m ================== phase I : Execution time : 0.12480 ================== phase II : Execution time : 0.01560 ================== phase III : Thinning - separateA Thinning - separateB Thinning - orient_edges Infering directions 0 boucles Execution time : 0.10920 score_Phase_3 = -6.0994e+003 Report genered in : ans = C:\Program Files\MATLAB\R2010b\BNT_SLP\examples Warning: Direct access of structure fields returned by a function call (e.g., call to test_bnpc_asia) is not allowed. See MATLAB 7.10 Release Notes, "Subscripting Into Function Return Values" for details. ??? Attempt to reference field of non-structure array.
0
1
0
0
0
0
I'm hoping to write a program to help me optimize on a 2d grid. In this grid, there are "blocks" which have a range that determines its area of effect. Many blocks can be placed on the grid. Each block may take up more than 1 tile, but is always square. I want to find out the maximum amount of times the area of effect can overlap a single XY position. I need to figure this out for 36 combinations (4 block types - 1x1, 2x2, 3x3, and 4x4, and ranges 1-9) The area of effect is always in a square pattern. In the example below, the letters are the blocks, and the numbers are where the area of effect is. A is a 1x1 block that has an area of effect of 1. B is a 1x1 block with an area of effect of 2. And C is a 2x2 block with an area of effect of 1. X X X X X X 1 1 1 X X 1 A 1 X X 1 1 1 X X X X X X X X X X X X X X 2 2 2 2 2 X X 2 2 2 2 2 X X 2 2 B 2 2 X X 2 2 2 2 2 X X 2 2 2 2 2 X X X X X X X X X X X X X X X 1 1 1 1 X X 1 C C 1 X X 1 C C 1 X X 1 1 1 1 X X X X X X X I can put as many blocks on the grid as I want, and I want to find out how many times the area of effect overlaps a target tile. For example, if I have an A tile (1x1 with 1 range), I maximize the area of effect by surround the target T. So the answer here would be 8. X X X X X X A A A X X A T A X X A A A X X X X X X Anyone know how I can figure this out for the other combinations? Thanks!
0
0
0
0
1
0
I've got a pretty big A* pathfinding function that gets called frequently and has to be put in another thread because otherwise it will make my game stutter. I come from a Java background, and recently read a discussion about the speed of HashMap's (essentially the equivalent of NSDictionary) and the different implementations you can use. I'm curious how fast NSDictionary is and whether anyone has found it to be viable option for dealing with lots of immediate and temporary object allocations, or whether it's too slow for that. Currently I'm using an NSMutableArray for the open and closed lists in the A* algorithm - I would be replacing the closed list with NSMutableDictionary due to the O(1) setObject:forKey and removeObject:forKey, and also creating an NSMutableDictionary that "mirrors" the open list. The pathing data is stored in a big NSMutableArray - I would leave this as-is because index access is fast enough (of course). So my question is... would this be a noticeable speed improvement or should I roll my own lists and/or maps? I'm just not sure what NSDictionary does and I'd like to know.
0
1
0
0
0
0
I was trying to write an algorithm for given problem: we are given a set of numbers- {n1,n2,n3,n4,n5......} and we have to check that can we derive a number(Say X) using addition and subtraction by given numbers. X will always be less than all elements of the given set. Eg. Set: {2,3,4,6,9} given number: 1, Result: Yes 9-4-4 =1 Set: {3,4,6,9} given number: 2, Result: Yes 6-4 = 2 Thanks in advance.
0
0
0
0
1
0
I am in need of parsing a small subset of English for one of my project, described as a context-free grammar with (1-level) feature structures (example) and I need to do it efficiently . Right now I'm using NLTK's parser which produces the right output but is very slow. For my grammar of ~450 fairly ambiguous non-lexicon rules and half a million lexical entries, parsing simple sentences can take anywhere from 2 to 30 seconds, depending it seems on the number of resulting trees. Lexical entries have little to no effect on performance. Another problem is that loading the (25MB) grammar+lexicon at the beginning can take up to a minute. From what I can find in literature, the running time of the algorithm used to parse such a grammar (Earley or CKY) should be linear to the size of the grammar and cubic to the size of the input token list. My experience with NLTK indicates that ambiguity is what hurts the performance most, not the absolute size of the grammar. So now I'm looking for a CFG parser to replace NLTK. I've been considering PLY but I can't tell whether it supports feature structures in CFGs, which are required in my case, and the examples I've seen seem to be doing a lot of procedural parsing rather than just specifying a grammar. Can anybody show me an example of PLY both supporting feature structs and using a declarative grammar? I'm also fine with any other parser that can do what I need efficiently. A Python interface is preferable but not absolutely necessary.
0
1
0
0
0
0
If I have a general function,f(z,a), z and a are both real, and the function f takes on real values for all z except in some interval (z1,z2), where it becomes complex. How do I determine z1 and z2 (which will be in terms of a) using Mathematica (or is this possible)? What are the limitations? For a test example, consider the function f[z_,a_]=Sqrt[(z-a)(z-2a)]. For real z and a, this takes on real values except in the interval (a,2a), where it becomes imaginary. How do I find this interval in Mathematica? In general, I'd like to know how one would go about finding it mathematically for a general case. For a function with just two variables like this, it'd probably be straightforward to do a contour plot of the Riemann surface and observe the branch cuts. But what if it is a multivariate function? Is there a general approach that one can take?
0
0
0
0
1
0
I need to approximate a table-defined 2D-function like that x0 y0 x1 y1 ... xn yn for every point I have a "weight" (root-mean-square error for this measure). I need to write a function like this: typedef std::vector< double > DVector; void approximate2D( const DVector & x , const DVector & y , const DVector & weights , double newMeasuredX , double newMeasuredY , double newMeasuredWeight , double & outApproximatedX , double & outApproximatedY ); to get one value ( outApproximatedX; outApproximatedY ) depend on previous values and new measured value. Root-mean-square (RMS) error should be used as follows: if a RMS error is minimal, then desired function should go close to this point, if a RMS error is maximal, then this point should be use with a minimal contribution. Approximation should be linear (I think), since I know, that desired function is a straight line. Googled about a half of a day, and did not found any suggestions. Thank you.
0
0
0
0
1
0
Hello I have a gridview which looks like: Boundfield(string), Boundfield(decimal), button1, button2, button3, button4, button5, label button1, 2, 3, 4, 5 and label are inside a template field. Based on what button is pressed: Button 1 - 100% which should work out 100% of boundfield(decimal) = label1 Button 2 - 80% which should work out 80% of boundfield(decimal) = label Button 3- 60% which should work out 60% of boundfield(decimal) = label Button 4 - 40% which should work out 40% of boundfield(decimal) = label Button 5 20% which should work out 20% of boundfield(decimal) = label This should work out seperate sums based on each row I can imagine it to auto generate the sum for every label in the gridview which i don't want. Is this possible and if so how could you go about doing it?
0
0
0
0
1
0
I could use two loops to check for all combinations of two integers that less than p prime, but it's very inefficient. Is there a better algorithm to approach this problem? Any idea? Where p mod 4 = 1. Thanks,
0
0
0
0
1
0
I've been working with images in the frequency domain (by taking the DFT or FFT of an image) and I know that convolution in the space domain is multiplication in the frequency. So my question is, if I wanted to apply a specific kernel (lets say a 9x9 smoothing kernel) in the space domain, I would just convolve the whole image by the 9x9 filter. Now, if I wanted to do the same thing in the frequency domain, do I take the FFT of both the image and the kernel? Then how/what do I multiply? After I have that new set of data (image multiplied by kernel), I just reverse the direction of the FFT and that should give me the same result as the kernel convolved with the image in the space domain, right? Thanks for any help!
0
0
0
0
1
0
I am writing a c program. I have an unsigned integer (16bit) whose value could be anything at any time and I have a signed char (8bit) whose value could be anything at any time, within the obvious limits of the data types. I need to add the signed char to the unsigned int, the result being an unsigned int, and if the value overflows either past 0xFFFF or below 0x00, i need the result to equal the limit (either 0x00 or 0xFFFF). I want to know what would be the fastest approach to doing this? My approach is shown below but it uses a long data type and thus long binary arithmetic so I am guessing that there is a faster way... long i; unsigned int result; i = someUINT + someCHAR; if(i <= 0) { result = 0; } else if(i >= 0xFFFF) { result = 0xFFFF; } else { result = (unsigned int)i; } EDIT: I am using a 16bit MCU (PIC24HJ series) and the Microchip C30 compiler.
0
0
0
0
1
0
You are given the radius of a circle, as well as a point P in the circle( x,y), how do you write a function to return an x number of points( x,y), all on the circumference of the given circle. Also, how do you go about finding the angle between each generated point and point P.
0
0
0
0
1
0
I have some text that was generate by another system. It combined some words together in what I assume was some sort of wordwrap by-product. So something simple like 'the dog' is combine into 'thedog'. I checked the ascii and unicode string to see is there wasn't some unseen character in there, but there wasn't. A confounding problem is that this is medical text and a corpus to check against aren't that available. So, real example is '...test to rule out SARS versus pneumonia' ends up as '... versuspneumonia.' Anyone have a suggestion for finding and separating these?
0
1
0
0
0
0
I'm trying to make my own implementation of the FastICA algorithm based on the paper here: http://www.cs.helsinki.fi/u/ahyvarin/papers/NN00new.pdf. I need some help w/ the math though. In the middle of page 14 there is an equation that looks somewhat like w+ = E{ xg(w^Tx) } - E{ g[prime]( w^T x)} w What does the E mean? Back from my probability days I recall that it is the "expected value" of a random variable but it doesn't make sense to me what the expected value of a vector is. Thanks, mj
0
0
0
0
1
0
Given a object which may move forward, backward, left and right at a given X,Y point. How to efficiently direct the object to a X,Y point using the given movement mechanics in the most efficient and human natural way. The object is available for movement in real time, you may tell them to "startMoving" and "stopMoving". Though as a additional twist and the part I am having trouble with, is the facing of the object is never known, only its current location is known, so the algorithm must "detect" direction. The location of the object is updated in a separate thread in 500-1second intervals. A "Request" to update the location within the algorithm made be made at any point, but it is not immediately available and the algorithm must keep that in consideration. Doing something like requestAndWaitForCoordUpdate() is perfectly acceptable, however likely not needed. Here is some example code: public int[] currentCoords; public void movement() { currentCoords[0] = 1005; // starting y coord currentCoords[1] = 1007; // starting x coord moveTo(1050, 1025); } public void moveTo(int x, int y) { ... how? } public void threadUpdatingCoords() { ... periodically check for source coord updates ... between 200ms and 1000ms apart. }
0
1
0
0
0
0
decimal result = 100 * 200; vs decimal result = Decimal.Multiply(100, 200);
0
0
0
0
1
0
Given a object which may move forward, backward, left and right at a given X,Y point. How to efficiently direct the object to a X,Y point using the given movement mechanics in the most efficient and human natural way. The object is available for movement in real time, you may tell them to "startMoving|Direction|()" and "stopMoving|Direction|()". Though as a additional twist and the part I am having trouble with, is the facing of the object is never known, only its current location is known, so the algorithm must "detect" direction. The location of the object is updated in a separate thread in 500-1second intervals. A "Request" to update the location within the algorithm made be made at any point, but it is not immediately available and the algorithm must keep that in consideration. Doing something like requestAndWaitForCoordUpdate() is perfectly acceptable, however likely not needed. In addition, no obstacles appear, it can be assumed you are on a MOSTLY open plane, stray to far from the direct straight line between the paths and you may run into obstacles. It is safe to assume that 1/4th the distance between a target and source, should be available in width on a given direct path. I would also mention I am not sure A* applys in this scenario, if it does I am unsure how to implement it given the constraints. The only real variable here is the facing of the object. Here is some example code: public int[] currentCoords; public void movement() { currentCoords[0] = 1005; // starting y coord currentCoords[1] = 1007; // starting x coord moveTo(1050, 1025); } public void moveTo(int x, int y) { ... how? } public void threadUpdatingCoords() { ... periodically check for source coord updates ... between 200ms and 1000ms apart. }
0
1
0
0
0
0
I am currently writing a calculator program in java. It is my first java program, I am used to c++. I have noticed that doubles in java are not at all like doubles in c++. try this in java and c++ 4.1*3 that/.1 it should be 12.3 then 123, and c++ gives this result but java gives 12.299999999999999 and 122.99999999999999 How can I do math like in c++ with doubles, I understand that anything you would use 12.299999999999999 in a program at all would make no difference compared to 12.3, but when a user is reading the numbers this is very ugly. I have looked into the BigDecimal class but I cannot do trig and logarithms and whatnot with that class
0
0
0
0
1
0
Does anyone know how to show mathematical equations in QTextEdit written in any format (TXT, MathML, MML, LaTeX, HTML, XML or anything) using only Python, that is without using 3rd party packages like Latex itself.? I tried to find the MathML Widget from Qt but it disappeared from their web site and I couldn't find it anywhere. I'm not fussed about the equation source (either a string or a file). I just can't figure out how to show them nicely (the same way as they appear on a web page, e.g. http://en.wikipedia.org/wiki/MathML). My QTextEdit currently gets an HTML string. I tried embedding the MathML example from that Wikipedia article, but it doesn't show it properly, it ignores all those MathML tags. Will really appreciate your help. Thank you.
0
0
0
0
1
0
I had a trouble in my database here, I use Firebird 1.5.3 and it work just fine until noe to read or write in normal way, but when I run a procedure, I got blank row result and the following message : Arithmetic exception, numeric overflow, or string truncation. SQL Code: -802 IB Error Number: 335544321 So I compared it with my backup db a month ago, it worked just fine, I get data in rows. To ensure my code wasnt change, I copy paste both procedure in WinMerge (diff comparer) but nothing diffrent. To ensure my error came from data, I run my procedure for old dated transaction (1 year old data), still I get those message. I check the aritmethic logic in procedure, modifying, but no luck. Did anyone can help with this? Thx a bunch,
0
0
0
0
1
0
9 9 9 9=20, you can add +,-,x,/ or () between the number. how to make them equal.
0
0
0
0
1
0
I'am reading this example, but Could you explain a little more, I dont get the part when it says "then we Normalize"... I know P(sun) * P(F=bad|sun) = 0.7*0.2 = 0.14 P(rain)* P(F=bad|rain) = 0.3*0.9 = 0.27 But where do they get W P(W | F=bad) ----------------- sun 0.34 rain 0.66 Example from
0
1
0
0
0
0
So I'm trying to dynamically calculate the number of SMS messages that will be sent for a given message length. SMS messages are chunked into 160 byte (character) chunks. I use MOD 160 <= 1 because I need to account for adding and subtracting text. For performance reasons I only want to do the numMsgs calculations near the boundaries: 0, 1, 160, 161, 320, 321, ... The problem is at a msgBody length of 160 the rounding operation evaluates to 2 (160/160 = 1 + 0.5 rounded up). At multiples of 160 + 1 it should evaluate to the next highest integer because any 160 bytes + 1 byte equals a whole additional message. I have made this work by using an OR operator and == 1 OR == 159. It increments and decrements correctly, but it only decrements at multiples of 160 -1 which is not correct. Also, I can put IF logic inside the outer logic to simply subtract 1 if the MOD evaluates to 0 (zero), but that seemed kludgey and I'd rather learn the pattern I may be missing from my quiver :) if (msgBody.length() % 160 <= 1) { numMsgs.setText(Math.round(msgBody.length() / 160 + 0.5)); }
0
0
0
0
1
0
Assume you have n users and know that n grows by a fixed number of users c per day and viral growth rate of k per day, where k is expressed as a percentage of n. How can you tell how many days it will take for the userbase to grow to size x, where x > n? This is a compound interest problem, but I don't know how to do it with the addition of the constant factor c.
0
0
0
0
1
0
I've found a public domain latin<->portuguese dictionary in PDF which I'd like to convert to plain text, parse and use as the database of a program. After some testing, however, I got a little skeptical. Take a look at the original file and at the resulting text of gocr. Is there any hope that I might reach 99%+ accuracy in some method? I thought of reCaptcha's database, but I guess it is Google's property, isn't it? Thanks!
0
1
0
0
0
0
in my app a user is able to enter text, which later I then search from and extract based on future submission. Problem is users can sometimes have a type or forget a period, etc... is there a way in ruby to say match with X% confidence level? Meaning if the match goal is 500 characters, and a match was found with 490 characters, match it, versus not matching anything? Thanks
0
0
0
1
0
0
The operation should try and keep the answer of the same type as the original inputs, thus if the holder started of with a Double then the result should also be a double. If inputs contain holders of different number types then it should auto widden etc. There should be a single type of Holder with getters to return the result as an integer, double, bigdecimal, big integer etc with exceptions thrown if conversion fails. Code should look like Bigdecimal. Ideally immutable Code shouldnt know or care whats inside the holder, operations just work until conversion is needed at a later stage. Unfortunately BigDecimal is not really complete for my needs its missing many key functions eg: sine, log and most of the static helpers on Math. ApacheCommonsMath Axelcb made a suggestion to use the apache commons math library. The main class of use in my case seem to be DFP. Examining DFP there is no simple way to pass a BigDecimal/BigInteger and build a DFP. It would be nice if precision would also be a parameter and used during the suck in process. none of the functions (like multiply) accept a context w/ a precision and rounding just like BigDecimal. I really dont understand the reasoning for the clunky way precisions and rounding are handled. What is a DfpField, what exactly does it do and why are there fields in a DFP ??? Please dont tell me this Calendar again. there are no methods to export to a BigDecimal or BigInteger dfp is this the original inspiration for apache commons math DFP class ? the first concern about import from a BigDecimal or BigInteger is lacking. there are no methods to export to a BigDecimal or BigInteger
0
0
0
0
1
0
Why is there a a property in Javascript that returns the approximate square root of 2. Isn't Math.sqrt(2) enough? There is also a property that returns the square root of 0.5. I'm wondering out of pure curiosity.
0
0
0
0
1
0
For given n, find the subset S of {1,2,...,n} such that all elements of S are coprime the sum of the elements of S is as large as possible Doing a brute force search takes too long and I can't find a pattern. I know that I can just take all the primes from 1 to n, but that's probably not the right answer. Thanks.
0
0
0
0
1
0
I have a simple machine learning question: I have n (~110) elements, and a matrix of all the pairwise distances. I would like to choose the 10 elements that are most far apart. That is, I want to Maximize: Choose 10 different elements. Return min distance over (all pairings within the 10). My distance metric is symmetric and respects the triangle inequality. What kind of algorithm can I use? My first instinct is to do the following: Cluster the n elements into 20 clusters. Replace each cluster with just the element of that cluster that is furthest from the mean element of the original n. Use brute force to solve the problem on the remaining 20 candidates. Luckily, 20 choose 10 is only 184,756. Edit: thanks to etarion's insightful comment, changed "Return sum of (distances)" to "Return min distance" in the optimization problem statement.
0
1
0
1
0
0
I heard that Google hosted (or will host) a web classification competition and they provided a large (170k+ documents) dataset of web sites that were classified into multiple categories (sports, computers, science, etc.) I tried looking around in their Summer of Code web site for 2009 through 2011, but didn't find anything. Does anybody know where I can get that dataset?
0
1
0
1
0
0
I am trying to create a combobox that contains text and when each text is chosen the text will equal a decimal and later be used in a math code. I am using C# inside Visual Studio. I am a beginner and any help will be greatly appreciated. Thanks, Royal
0
0
0
0
1
0
I have a texture with 3 specific points on it (in 2d pixel coordinates) mapped to 3d points in a text file. I need to then create the quad to encompass the whole texture but am unsure of how to do this. Any ideas? For example, the texture is 128x128 pixels, a point on the texture (10,10) is known to be mapped to a 3d coordinate. This goes for the other 2 known coordinates. What I want though is vert coords to encompass the whole texture.
0
0
0
0
1
0
Let S be a set of 10 digit numbers. Given any two numbers v and w in S, I'd like to know if there is a sequence of numbers v=u_0, u_1, ... , u_k=w such that: each u_i is in S for each i=1,..,k, the numbers u_{i-1} and u_i differ in exactly one position As a plus, it would be even better to find an algorithm to find the shortest such sequence. Ideally, I would prefer a C (or pseudo-code) solution, but I really, really appreciate any and all suggestions on this one! Thanks!
0
0
0
0
1
0
I have a Javascript function that calculates a value and re-inserts the value into a <td> while also injecting the value into a hidden <input>. This is my function: $("input[name^='policies']:checkbox").change(function() { var el = $(this); if (el.is(":checked")) { no_policies++; } if (el.is(":not(:checked)")) { no_policies--; } subscription = no_policies*policy_cost; first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2); alert(first_payment); $("td#first_payment").text("R "+first_payment); $("input#first_payment_txt").val(first_payment); $("td#subscription").text("R "+subscription.toFixed(2)); }); Everything works on IE8 up until this statement: first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2); I suspect IE8 is having trouble with Math.ceil, is that true? Also, is there any other function/method I can use to circumvent this? Thanks in advance.
0
0
0
0
1
0
For the code: #define e 2.71828183; double p ( int x ) { return 1 / ( 1 + pow ( e, -1.0 * x ) ); } I get: math.cpp: In function ‘double p(int)’: math.cpp:11: error: expected ‘)’ before ‘;’ token math.cpp:11: error: expected ‘)’ before ‘;’ token math.cpp:11: error: expected primary-expression before ‘,’ token math.cpp:11: error: expected ‘;’ before ‘)’ token
0
0
0
0
1
0
I have the following code and have tried everything to parse all the numbers so that IE doesn't throw a fit: var firt_payment = 0.0; var subscription = 0.0; var no_policies = 0; var policy_cost = 100.0; if (typeof interval == "undefined") { var interval = 0; } var days_left = daysLeftMonth(interval); var days_month = daysInMonth(); $("input[name^='policies']:checkbox").change(function() { var el = $(this); if (el.is(":checked")) { no_policies++; } if (el.is(":not(:checked)")) { no_policies--; } subscription = Number(no_policies*policy_cost); var interim_val = 0.0; if (no_policies > 0) { interim_val = no_policies*(policy_cost/days_month)*days_left; } first_payment = Math.ceil(subscription+interim_val).toFixed(2); $("td#first_payment").text("R "+first_payment); $("input#first_payment_txt").val(first_payment); $("td#subscription").text("R "+subscription.toFixed(2)); }); Does anyone have an answer for me as to why first_payment = Math.ceil(subscription+interim_val).toFixed(2); does not get calculated on IE8? Please, I'm desperate over here. Thanks in advance.
0
0
0
0
1
0
Write a program that calculates Euler’s number e. To do this, first write a function that takes a parameter n, and returns the result (1+1/n)n. The limit of this function approaches e as n approaches infinity. In your main program, write a loop that calls this function with increasing values of n. On each iteration, multiply n by 2 (if you just add 1 to n each time, the algorithm won' work) and stop when the your new approximation and your previous approximation differ by less than 1e-8. Now you have a pretty good estimate. So in main(), print your best approximation and the number n that generated it. I have done everything up until the for-loop. I don't quite understand how am I supposed to stop for-loop after new and previous numbers are approximately the same. Here is my function: double euler_finder(double n) { return pow((1+1/n), n); } And here is my for-loop in the main method, where ??? is where I'm having a problem: for (int i=0; i<????; i*=2) { } EDIT: The solution has been posted so here how it looks like: #include <iostream> #include <iomanip> #include <cmath> using namespace std; double euler(int n); int main() { int trialN = 4; double guess1, guess2; guess1 = euler(1); guess2 = euler(2); while( abs(guess1-guess2) > 1e-8 ) { cout<< trialN << " " << guess2<<endl; guess1 = guess2; guess2 = euler( trialN ); trialN*=2; } cout<<setprecision(8)<<"e is approximately "<<guess2<<" and we got it with a value of "; cout<<trialN<<" for n"; return 0; } double euler(int n) { return pow((1+1.0/n), n); } Output: 4 2.25 8 2.44141 16 2.56578 32 2.63793 64 2.67699 128 2.69734 256 2.70774 512 2.71299 1024 2.71563 2048 2.71696 4096 2.71762 8192 2.71795 16384 2.71812 32768 2.7182 65536 2.71824 131072 2.71826 262144 2.71827 524288 2.71828 1048576 2.71828 2097152 2.71828 4194304 2.71828 8388608 2.71828 16777216 2.71828 33554432 2.71828 67108864 2.71828 134217728 2.71828 e is approximately 2.7182818 and we got it with a value of 268435456 for n
0
0
0
0
1
0
the problem is best explained with an example: http://dl.dropbox.com/u/1013446/distortedcoordinatespace.exe drag and drop the little red square inside the small square on the right. it corresponds to the red square in the big quadrilateral on the left. you can also drag the 4 corners of the big quadrilateral on the left to see how it occupies a distorted version of the space within the square. given the absolute coordinates for the 4 points of a square and the coordinates of an arbitrary point within the square, it's simple matter to remap the point's coordinates to an arbitrary quadrilateral. what I want is to be able to start off with an arbitrary quadrilateral, and be able to do the same thing, transforming the quadrilateral to any other 4 sided shape, but maintaining the relative distorted position of the point, so given the 4 absolute coordinates of each of 2 irregular quadrilaterals, A and B, how can I convert the coordinates of point C given it's absolute coordinates? also helpful, would be any terminology that I'm missing here for what these transformations would be called, because I'd like to look into them more ok, I'm attempting to implement btilly's solution, and here's what I have so far: #include<complex> #define cf complex<float> cf i=sqrt(complex<float>(-1)); cf GetZ(float x,float y) { return cf(x)+(cf(y)*i); } cf GetPathIntegral(cf p1,cf p2,cf q1,cf q2, int n) { cf sum; for (int index=0;index<=n;index++) { cf s=cf(float(index)/float(n)); cf weight; if (index==0||index==n) weight=1; else if(index%2) weight=4; else weight =2; sum+=(((cf(1)-s)*q1)+(s*q2))*(p2-p1)*weight; } return sum/cf((3.0*(n-1.0))); } before I move on from here, I want to make sure I'm right so far... also, this paragraph confused me a bit: OK, so we can do path integrals. What is the value of that? Well suppose we take a random point z0 = x + iy somewhere in our region. Suppose that f(z) is defined on the path. Then the Cauchy Integral Formula says that the integral around our region (which is the sum of 4 piecewise integrals that we know how to do) of f(z)/(2 * π * i * (z - z0)) is a really nice function that is going to match our original function on the boundary. what does the function do exactly?
0
0
0
0
1
0
Hope and pray that you all must well. I have a scenario, in which i have to write a very large set of relational/combinational data, I am looking for a implementation technique which must be super fast. Its something like an expert system in AI. I have 4 entities, Questions, Options, Benefits and Scenarios: Each question can have multiple options Each option can relate to single question On any combination of options a benefit is allocated, the allocation is called scenario a scenario can related to any number of options a scenario can relate to any number of benefits Each benefit can be included in multiple scenarios Now for instance we look for an example: We have 4 questions, q1, q2, q3, q4 q1 have 3 options q1o1, q1o2, q1o3 q2 have 4 options q2o1, q2o2,q2o3,q2o4 q3 have 5 options q3o1, q3o2,q3o3,q3o4, q3o5 q4 have 2 options q4o1, q4o2 scenario 1: for combination of [q1o1,q201] a benefit b1 is allocated scenario 2: for combination of [q1o1,q201,q303] a benefit b2 is allocated scenario 3: for combination of [q201,q304] a benefit b3 is allocated scenario 4: for combination of [q304,q401] a benefit b4 is allocated scenario 5: for combination of [q402] a benefit b5 is allocated scenario 6: for combination of [q1o2,q2o2,q3o1,q4o1] a benefit b5 is allocated So in this way ( (3+1) C 1 x (4+1) C 1 x (5+1) C 1 x (2+1) C 1 ) - 1 ( 4 x 5 x 6 x 3 ) - 1 360 - 1 359 scenarios can be build. where as C denote to Combination. And if questions goes to 25 and each question should have 5 options ((5+1) ^ 25 - 1) 6 ^ 25 -1 28430288029929701375 scenarios can be build I am looking for a best way to store this relational/combinational data to the database and want to access it back. Will wait for response of you guys.
0
0
0
0
1
0
Project Euler problem 14: The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) n → 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1 It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1. Which starting number, under one million, produces the longest chain? My first instinct is to create a function to calculate the chains, and run it with every number between 1 and 1 million. Obviously, that takes a long time. Way longer than solving this should take, according to Project Euler's "About" page. I've found several problems on Project Euler that involve large groups of numbers that a program running for hours didn't finish. Clearly, I'm doing something wrong. How can I handle large groups of numbers quickly? What am I missing here?
0
0
0
0
1
0
I am stuck with a very simple question about minimizing an optimum design problem. Here is the question: Minimize f(x,y) = (x-4)^2 + (y-6)^2 subject to 12 >= x + y x >= 6, y>= 0
0
0
0
0
1
0
I'm learning Ruby for fun, and for creating websites also (but that's irrelevant). While playing with it, i noticed something "weird" When I compute 4.21 + 5 with irb, it answers 9.21 (weird, right?) when I compute 4.23 + 5, it gives 9.23 (waw, that's definitely weird). and when i type 4.22 + 5, it answers 9.21999... (w...wait! that's really weird). Hence my question: what's going on? I'd understand this behavior with division or really big numbers, but in this simple case....??? Does it mean that i can't develop an accounting app with Ruby? Is there a patch or something to be applied? (to my brains, most likely)
0
0
0
0
1
0
Given a 3D position of a camera, 3D target position of the camera (the point the camera points to), far plane distance from the camera, field of view and aspect ratio, how can I calculate the four 3D points in the far plane? This should be possible with basic trigonometry but I'm not getting the exact right results.
0
0
0
0
1
0
I'm reading a signed 64 bit integer (Java long) from the network in Flash+ActionScript3, and storing it as two uint's (first and last 32 bits). var l:LongNumber = new LongNumber(); l.msb = socket.readUnsignedInt(); l.lsb = socket.readUnsignedInt(); How can I convert it into the actual number as a Number? I'm aware Number can contain only 53 bit integers, not 64, but it's enough (though being able to throw an Error when converting larger numbers would be nice).
0
0
0
0
1
0
I've been playing around with an accelerometer with 3 axis: X, Y and Z. It says on the supplier's site that it measures gravitational force. I'm sending this data to the blender games engine where I am rotating a cube in real time depending on the data values coming from the accelerometer. However the values coming through don't seem to match up. On each axis the accelerometer spits out values from -700 to 700 on each axis and I need to convert these values to something I can use in Blender. My maths knowledge is not up to scratch so I don't know where to start with this one. If anybody could shed some light on this, that would be great. Many thanks Will EDIT Currently I'm using a bit of python code to convert the rotation values to a matrix: def reorient(alpha, beta, gamma): a = math.cos(alpha) b = math.sin(alpha) c = math.cos(beta) d = math.sin(beta) e = math.cos(gamma) f = math.sin(gamma) ad = a*d bd = b*d matrix = [[c*e, -a*f+b*d*e, b*f+a*d*e], [c*f, a*e+b*d*f, -b*e+a*d*f], [-d, b*c, a*c]] return matrix I am then using setOrientation(matrix) to affect the rotation of the cube. However I am currently throwing the wrong values into the matrix reorient() function
0
0
0
0
1
0
I have created a solar system generator in Java. I was wondering, if I have an asteroid in the sytem and want to check if it has coliided with a planet would I just get the distance between the asteroid and each planet and if the distance minus the radius was 0 or less it would be a collision. Is that the correct math? Thanks
0
0
0
0
1
0
Questions I want to classify/categorize/cluster/group together a set of several thousand websites. There's data that we can train on, so we can do supervised learning, but it's not data that we've gathered and we're not adamant about using it -- so we're also considering unsupervised learning. What features can I use in a machine learning algorithm to deal with multilingual data? Note that some of these languages might not have been dealt with in the Natural Language Processing field. If I were to use an unsupervised learning algorithm, should I just partition the data by language and deal with each language differently? Different languages might have different relevant categories (or not, depending on your psycholinguistic theoretical tendencies), which might affect the decision to partition. I was thinking of using decision trees, or maybe Support Vector Machines (SVMs) to allow for more features (from my understanding of them). This post suggests random forests instead of SVMs. Any thoughts? Pragmatical approaches are welcome! (Theoretical ones, too, but those might be saved for later fun.) Some context We are trying to classify a corpus of many thousands of websites in 3 to 5 languages (maybe up to 10, but we're not sure). We have training data in the form of hundreds of websites already classified. However, we may choose to use that data set or not -- if other categories make more sense, we're open to not using the training data that we have, since it is not something we gathered in the first place. We are on the final stages of scraping data/text from websites. Now we must decide on the issues above. I have done some work with the Brown Corpus and the Brill tagger, but this will not work because of the multiple-languages issue. We intend to use the Orange machine learning package.
0
1
0
1
0
0
So I have a string pn2 = -.433222082282652077 I need to parse it with reg exp into 2 strings (put values into 2 variables) First A: pn2 Second B: -0.433222082282652077 How to do such thing with maple?
0
0
0
0
1
0
If I have a system of a springs, not one, but for example 3 degree of freedom system of the springs connected in some with each other. I can make a system of differential equations for but it is impossible to solve it in a general way. The question is, are there any papers or methods for filtering such a complex oscilliations, in order to get rid of the oscilliations and get a real signal as much as possible? For example if I connect 3 springs in some way, and push them to start the vibrations, or put some weight on them, and then take the vibrations from each spring, are there any filtering methods to make it easy to determine the weight (in case if some mass is put above) of each mass? I am interested in filtering complex spring like systems.
0
0
0
0
1
0
I'm trying to optimize some functions and I realized that I know next to nothing about how long certain things take. I can ask all the questions here, but I'd rather just find a good article on the subject if anyone knows one. I'm using IAR to write a program in C for an ATMEL SAM7S processor. I have a sort function that takes 500uS or so, and I wanted to see if I could speed it up. I could also just post it here but I was hoping to learn for myself. Like, is it any faster to subtract two 16 bit integers than it is to subtract two 32 bit integers? And how long does an operation like that take? Just one cycle or more? How long does multiplication take compared to subtraction? Anyone know a place to look? I tried googling for some stuff but I couldn't come up with any useful search terms. If anyone has an ideas on my specific function, I can post details. I'm basically trying to match two analog values to the closest index in a table of calibrated values. Right now I iterate through the whole table and use least squares to determine the closest match. Its pretty straightforward and I'm not sure there is a faster way without applying some extra logic to my table. But if I at least knew how long certain things took, I could probably optimize it myself.
0
0
0
0
1
0
Suppose that one has three polls in which the options are the same ... Option 1 Option 2 Option 3 being that in a survey done the following result POLL RESULT 1 Option 1 - 30% Option 2 - 20% Option 3 - 50% In the second poll gave the following result POLL RESULT 2 Option 1 - 33% Option 2 - 18% Option 3 - 49% And third in the poll gave the following result POLL RESULT 3 Option 1 - 18% Option 2 - 22% Option 3 - 60% My question is, how to make an asp in sum, taking into account all these three polls, and riding an average percentage over the results ... or ... Calculating all the polls and pointing the final percentage, plus all the polls.
0
0
0
0
1
0
I want to get a list of: Sides of Right Triangle which are perfectly whole numbers.(where each sides less than 100) Example: //I want these combination to be printed 3, 4, 5 6, 8, 10 |'. 5, 12, 13 12 | '. 13 (Figure is just Example) . | '. . |______'. . 5 // I don't want these 1, 1, 1.414.... |'. . 1 | '. √ˉ2 = 1.414.... (Figure is just Example) . | '. |______'. 1 Update: I do like this: But this is very heavy code(regarding optimization) for(int i=1;i<100;i++) { for(int j=1;j<100;j++) { for(int k=1;k<100;k++) { if(i*i + j*j == k*k) { //print i, j, k } } } }
0
0
0
0
1
0
Suppose I have 3 sensors: sensor1, sensor2 and sensor3. The only variables I know are: Distance from sensor1 to origin is 36.05 Distance from sensor2 to origin is 62.00 Distance from sensor3 to origin is 63.19 Distance from sensor1 to sensor2 is 61.03 Distance from sensor1 to sensor3 is 90.07 Distance from sensor2 to sensor3 is 59.50 This is how it would look like if you had the positions: How can I calculate the position of every point using only those variables? This is not homework, just curiosity.
0
0
0
0
1
0
i have a checkbox that toggled with a button but i also need to add the its value to an equation, ONLY IF its checked. what i got right now is this, but it just add regardless of whether the checkbox is checked or not <html> <head> <script language=javascript> function validate(chk){ if (chk.checked == 1) chk.checked = 0; else chk.checked = 1; } </script> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> </head> <body> <form name="myform"> <input type="checkbox" name="ghj" id="ghj" value="100000">testing sheep<br> <input type="button" class="button-primary widget-control-save" name="Check_All" value="Check All" onmouseout="compute(this.form)" onClick="validate(ghj)"> <input type="text" id="rslt" name="rslt"> </form> <script type="text/javascript"> <!-- hide this script from old browsers function compute(form) { var test = parseInt(document.getElementById('ghj').value, 10) || 0; f = (test + 10); document.getElementById('rslt').value = f; } // done hiding from old browsers --> </script> </body> </html> if...else statements may work but if i have a longer form that would mean hundreds of possibilities, and i'd like a more efficient way..
0
0
0
0
1
0
Do you have an overview of what kind of Math is most useful for which field? For example, if a linux kernel developer, what type of math knowledge does one programmer need? For a driver developer, what type of Math is needed? It seems to me that except for computer science related fields and game programming, do other IT fields need hardcore Math?
0
0
0
0
1
0
I have to solve polynomial equation system which gives error as it has infinite solutions and i just require few solutions(any 2 or 3) so how can i get them? , Can i specify condition on solution like solutions whose values range between 1 to 10 so that i can get few value. Equations are actually long complicated but infinite solutions are due to "sin(0)" at root.
0
0
0
0
1
0
I'm having problem with Math.round() and Math.floor() in setInterval() function by using jQuery. This is my code: var number1 = 400; var up_up = setInterval( function (){ number1 = parseFloat(number1) + parseFloat(0.2548777); number1 = Math.round(number1); $('#number1').html(number1); }, 1000); The Math.round() or Math.floor() doesn't work, but when I use Math.ceil() it works fine, but I want round or floor.. Please help
0
0
0
0
1
0
I am interested in natural languge processing with python-django. My project requires creation of grammar productions at runtime. That means, whenever i ask a question or write a sentence, basic nlp steps like pos-tagging should be done and get them added to grammar productions or any other structure ( even if the words are not present in grammar) , so that i can do the further chunking and extraction of different nouns, verbs ,etc separately from that grammar. Please guide me the same.
0
1
0
0
0
0
I need to generate a random number, now this number needs to be somewhere between 10 and 120 seconds. Now, in C I could use Random to acomplish this, however I do not have access to that function. In an effort to try and be clever I have identified some random data, I have access to a wireless scan function (that this random number is actually eventually required for) which provides me the signal strength of each detected Wi-Fi signal. Using this I thought I could create a nice random number, however obviously this gives a very large sum which needs to be scaled down somewhat - this reduces the potential difference between different random numbers. The random number will be used as a backoff timer for different wireless devices trying to interconnect with eachother and obviously as random a figure as I can achieve the better. Any thoughts? Maybe there is an easier method of achieving this? Thanks for any tips. Edit: To make the post readable!
0
0
0
0
1
0
MOVED: Moving this question to math.stackexchange.com and closing it. I'm learning about the math invovled in PCA. For my purposes here, I'm just trying to understand a 90° rotation matrix. I get the concept of a rotation matrix, but when I look on wikipedia, the Wolfram Mathworld site, etc. I keep seeing the following defined as a 90° counter-clockwise rotation matrix: |0 -1| |1 0| but when I actually do the math, I seem to get the point(s) rotated clockwise around the origin: |1 2| |0 -1| |2 -1| |3 4| x |1 0| = |4 -3| Graphing the points (1,2) and (3,4), they're both in quadrant 1 (+,+). Graphing the resulting points, (2,-1) and (4,-3), they're both in quadrang 4 (+,-). The rotation works, but it seems clockwise, not counter-clockwise. What am I missing? Note A friend suggested that it's the coordinate system that's being rotated, but the wolfram site (linked above) seems to explicitly exclude that from being the cause of my misunderstanding (see (1) and (3) on the wolfram site). Any help greatly appreciated.
0
0
0
0
1
0
set windowSize 0 for {set i 0} {$i < 14} {incr i} { set $windowSize [expr $windowSize + [$tcp($i) set cwnd_]] } puts "$windowSize" This prints out zero, when the values being added are non zero. How to do this without a temp var? Holla if you love TCL. ...dead silence.
0
0
0
0
1
0
Which libraries/plugins are the best(fast/well-documented/etc) for designing and creating neural nets with backpropgation? Googling Ai4r Ai-Appp
0
1
0
0
0
0
In Greplin challenge level 3 it is required to count the number of subsets which sum up to another element in list. See Greplin and Challenge Description and Python code. I also found this code in javascript, but I found it far less understoodable than Python. My question is if there's some kind of Matlab command for finding all subsets of array, in similar way to the combinations library in python? Reffering to the challenge in your answer will be appreciated. I tried some kind of writing my own code to it, but it obviously didn't work so well. Nums = [3 4 9 14 15 19 28 37 47 50 54 56 59 61 70 73 78 81 92 95 97 99]; % Nums = [1, 2, 3, 4, 6]; SubsetCount = 0; for Ind = 1:length(Nums) maxNum = Nums(Ind); s = setdiff( Nums, maxNum ); NumSubsetsCountToIt = NumSubsetsCount( s, maxNum); SubsetCount = SubsetCount + NumSubsetsCountToIt; end disp(SubsetCount); function NumSubsetsCountToIt = NumSubsetsCount( Nums, SumUpNum ) global OptionsToGetTo NumSubsetsCountToIt = 0; validNums = Nums; if sum(validNums)==SumUpNum NumSubsetsCountToIt = 1; else for Ind=length( validNums ):-1:1 outNum = validNums(Ind); s = setdiff(validNums, outNum ); NumSubsets = NumSubsetsCount( s, SumUpNum-outNum ); NumSubsetsCountToIt = NumSubsetsCountToIt+NumSubsets; end NumSubsetsCountToIt = floor((NumSubsetsCountToIt+1)/2); end OptionsToGetTo(2, b) = NumSubsetsCountToIt;
0
0
0
0
1
0
I have a line that I draw in a window and I let the user drag it around. So, my line is defined by two points: (x1,y1) and (x2,y2). But now I would like to draw "caps" at the end of my line, that is, short perpendicular lines at each of my end points. The caps should be N pixels in length. Thus, to draw my "cap" line at end point (x1,y1), I need to find two points that form a perpendicular line and where each of its points are N/2 pixels away from the point (x1,y1). So how do you calculate a point (x3,y3) given it needs to be at a perpendicular distance N/2 away from the end point (x1,y1) of a known line, i.e. the line defined by (x1,y1) and (x2,y2)?
0
0
0
0
1
0
I am working on a geometry problem that requires finding the intersection of two parabolic arcs in any rotation. I was able to intesect a line and a parabolic arc by rotating the plane to align the arc with an axis, but two parabolas cannot both align with an axis. I am working on deriving the formulas, but I would like to know if there is a resource already available for this.
0
0
0
0
1
0
I'm coding an AI engine for a simple board game. My simple implementation for now is to iterate over all optional board states, weight each one according to the game rules and my simple algorithm, and selecting the best move according to that score. As the scoring algorithm is totally stateless, I want to save computation time by creating a hash table of some (all?) board configurations and get the score from there instead of calculating it on the fly. My questions are: 1. Is my approach logical? (and if not, can you give me some tips to better it? :)) 2. What is the most suitable thread-safe STL container for my needs? I'm thinking to use the char array (board configuration) as key and the score as value. 3. Can you give some tips for making my AI a killer one? :) edit: more info: The board is 10x10 and there are two players, each with 10 pawns. The rules are much like checkers.
0
1
0
0
0
0
I think you will loughing at me, but I need help here... I have a double (4.5234234) and need this in Int, but everytime without the numbers after the points. So it doesn't mathers if its 4.01 or 4.99 it should ever be 4 in Int. how to do that?
0
0
0
0
1
0
I'm doing a path-finding project as part of my 4th year software engineering degree. We're suppose to give visual representation to a bunch of multi-agent pathfinding algorithm. The simplest one is A* adapted for multiagents. Anyway our environment is a grid map where every cell can be either blocked or used as part of an agent's path. What I want to do is use animation to give a good representation of the final movement of the agent, but animating color change in my grid. I.E paint every step in the path for a second or so with some color to show how the agent moves. And the other thing I want to do is to represent the way the algorithm works by painting the changes in the open list and closed list of the A* algorithm while its doing its calculation. I'm using an adapted version of the observer design pattern to send events from my algorithm layer to my controller and GUI layer. What I want to do in the GUI layer is every time a tile is added to the open list, I want to have that cell painted in some color and then have it fade away according to a predefined timer or maybe later add a slider to control this timer. I looked at the code here. It seems pretty simple, the problem is that every tile animation has to be independent of the others to allow the algorithm and everything to keep running and different animations to start. So what's the best way to achieve the results I'm looking for? Should I just open a different thread for each animation or have a pre-made thread for each cell? Would that be an overkill for the application, since there can be up to 1000 cells and therefore close to 1000 threads performing animation. Another issue I think I might encounter is the fact that it might happen that a cell will start its color fading animation and then will have to restart and I don't want the two animations to go at the same time (only one thread performing animation for the same cell at the same time). I hope I was clear enough with what I'm trying to achieve, if someone has any ideas or thought it could really help me with my project.
0
1
0
0
0
0
I'm writing some software in which I need to compute bivariate densities of an x-y grid. Are there any libraries that might help me in Java for this? I've seen a lot of stuff in R, but nothing in Java.
0
0
0
0
1
0
What is available in terms of libraries / open-source software for processing and categorising natural language? I've got a database full of strings which are user descriptions of a particular item. I'd like to categorise these words to weed out the useless and make an educated guess as to what category the item fits into (e.g Technology, Sport, Music). I realise this a fairly specific request and my knowledge of natural language processing is very limited. I'm wondering what would be the best and if possible most computationally cheap way of making these sort of predictions? I would prefer to do this in Ruby however, Python or Java is also acceptable.
0
1
0
0
0
0
I once got the following as an interview question: I'm thinking of a positive integer n. Come up with an algorithm that can guess it in O(lg n) queries. Each query is a number of your choosing, and I will answer either "lower," "higher," or "correct." This problem can be solved by a modified binary search, in which you listing powers of two until you find one that exceeds n, then run a standard binary search over that range. What I think is so cool about this is that you can search an infinite space for a particular number faster than just brute-force. The question I have, though, is a slight modification of this problem. Instead of picking a positive integer, suppose that I pick an arbitrary rational number between zero and one. My question is: what algorithm can you use to most efficiently determine which rational number I've picked? Right now, the best solution I have can find p/q in at most O(q) time by implicitly walking the Stern-Brocot tree, a binary search tree over all the rationals. However, I was hoping to get a runtime closer to the runtime that we got for the integer case, maybe something like O(lg (p + q)) or O(lg pq). Does anyone know of a way to get this sort of runtime? I initially considered using a standard binary search of the interval [0, 1], but this will only find rational numbers with a non-repeating binary representation, which misses almost all of the rationals. I also thought about using some other way of enumerating the rationals, but I can't seem to find a way to search this space given just greater/equal/less comparisons.
0
0
0
0
1
0
I've got two players and I want to simulate a game between them. Both have some attributes (power, intelligence...) and different actions. The outcome of some action is based on attribute values and some luck factor. Algorithm: Construct a game tree of all possible moves for both players game tree would probably have limited depth Every level would belong to different player Use some heuristics at leaf nodes to find out probability of wining for player who has to make a move propagate probabilities up (like minimax algorithm does) choose a move with highest probability continue at the beginning of this algorithm So, basically this is minimax algorithm. I've got few question though: How to take luck factor in account? When I make one move, do I have to run whole algorithm again? (building the tree with +1 depth and new root node, calculate new probabilities...) Any other idea for simulating a battle? Thanks.
0
1
0
0
0
0