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
Most examples of the use of fixed point combinators involve functions that take integers to integers (e.g. factorial). In many cases the fixed point of a function over the real numbers will end up being an arbitrary rational or perhaps irrational number (a famous example is the logistic map http://en.wikipedia.org/wiki/Logistic_map). In these cases the fixed point may not be expressed in terms of primitive types (note though that Clojure does have support for ratios). I am interested in finding out about fixed point combinators (and their implementation!) that can compute fixed points of functions over these "exotic" types. Inasmuch as things like irrational numbers have decimal representation as infinite sequences, it seems like this computation must be evaluated lazily. Do any of these (putative) lazy evaluations yield good approximations to the true fixed points? My target languages are Python and Clojure, but I certainly wouldn't mind seeing any OCaml or Haskell implementations).
0
0
0
0
1
0
In a project I'm working on the user creates a circle and choose a point on that circle, P=(px,py). For the question's sake, let's assume the center of the circle is at (0,0). After the previous steps, the user can then change the eccentricity of the ellipse (as it was a circle it was actually an ellipse with e=0). While he changes the eccentricity, the ellipse should keep its center to (0,0), and the point P should stay on the ellipse's circumference. Thanks! Aviad.
0
0
0
0
1
0
Note that this question contains some spoilers. A solution for problem #12 states that "Number of divisors (including 1 and the number itself) can be calculated taking one element from prime (and power) divisors." The (python) code that it has doing this is num_factors = lambda x: mul((exp+1) for (base, exp) in factorize(x)) (where mul() is reduce(operator.mul, ...).) It doesn't state how factorize is defined, and I'm having trouble understanding how it works. How does it tell you the number of factors of the number?
0
0
0
0
1
0
I'm looking for the mathematical expression converting a 3D coordinate (x0,y0,z0) to a 2D (x1,y1) coordinate in a curvilinear perspective of radius R where the values of x1 and y1 are the angles of views {-90° .. +90°} of the original point. (source: ntua.gr) (image via http://www.ntua.gr/arch/geometry/mbk/histor.htm ) Thanks !
0
0
0
0
1
0
I'm trying to multiply A*B in 16-bit fixed point, while keeping as much accuracy as possible. A is 16-bit in unsigned integer range, B is divided by 1000 and always between 0.001 and 9.999. It's been a while since I dealt with problems like that, so: I know I can just do A*B/1000 after moving to 32-bit variables, then strip back to 16-bit I'd like to make it faster than that I'd like to do all the operations without moving to 32-bit (since I've got 16-bit multiplication only) Is there any easy way to do that? Edit: A will be between 0 and 4000, so all possible results are in the 16-bit range too. Edit: B comes from user, set digit-by-digit in the X.XXX mask, that's why the operation is /1000.
0
0
0
0
1
0
Bit of a random one, i am wanting to have a play with some NLP stuff and I would like to: Get all the text that will be displayed to the user in a browser from HTML. My ideal output would not have any tags in it and would only have fullstops (and any other punctuation used) and new line characters, though i can tolerate a fairly reasonable amount of failure in this (random other stuff ending up in output). If there was a way of inserting a newline or full stop in situations where the content was likely not to continue on then that would be considered an added bonus. e.g: items in an ul or option tag could be separated by full stops (or to be honest just ignored). I am working Java, but would be interested in seeing any code that does this. I can (and will if required) come up with something to do this, just wondered if there was anything out there like this already, as it would probably be better than what I come up with in an afternoon ;-). An example of the code I might write if I do end up doing this would be to use a SAX parser to find content in p tags, strip it of any span or strong etc tags, and add a full stop if I hit a div or another p without having had a fullstop. Any pointers or suggestions very welcome.
0
1
0
0
0
0
I have 3d mesh and I would like to draw each face a 2d shape. What I have in mind is this: for each face 1. access the face normal 2. get a rotation matrix from the normal vector 3. multiply each vertex to the rotation matrix to get the vertices in a '2d like ' plane 4. get 2 coordinates from the transformed vertices I don't know if this is the best way to do this, so any suggestion is welcome. At the moment I'm trying to get a rotation matrix from the normal vector, how would I do this ? UPDATE: Here is a visual explanation of what I need: At the moment I have quads, but there's no problem converting them into triangles. I want to rotate the vertices of a face, so that one of the dimensions gets flattened. I also need to store the original 3d rotation of the face. I imagine that would be inverse rotation of the face normal. I think I'm a bit lost in space :) Here's a basic prototype I did using Processing: void setup(){ size(400,400,P3D); background(255); stroke(0,0,120); smooth(); fill(0,120,0); PVector x = new PVector(1,0,0); PVector y = new PVector(0,1,0); PVector z = new PVector(0,0,1); PVector n = new PVector(0.378521084785,0.925412774086,0.0180059205741);//normal PVector p0 = new PVector(0.372828125954,-0.178844243288,1.35241031647); PVector p1 = new PVector(-1.25476706028,0.505195975304,0.412718296051); PVector p2 = new PVector(-0.372828245163,0.178844287992,-1.35241031647); PVector p3 = new PVector(1.2547672987,-0.505196034908,-0.412717700005); PVector[] face = {p0,p1,p2,p3}; PVector[] face2d = new PVector[4]; PVector nr = PVector.add(n,new PVector());//clone normal float rx = degrees(acos(n.dot(x)));//angle between normal and x axis float ry = degrees(acos(n.dot(y)));//angle between normal and y axis float rz = degrees(acos(n.dot(z)));//angle between normal and z axis PMatrix3D r = new PMatrix3D(); //is this ok, or should I drop the builtin function, and add //the rotations manually r.rotateX(rx); r.rotateY(ry); r.rotateZ(rz); print("original: ");println(face); for(int i = 0 ; i < 4; i++){ PVector rv = new PVector(); PVector rn = new PVector(); r.mult(face[i],rv); r.mult(nr,rn); face2d[i] = PVector.add(face[i],rv); } print("rotated: ");println(face2d); //draw float scale = 100.0; translate(width * .5,height * .5);//move to centre, Processing has 0,0 = Top,Lef beginShape(QUADS); for(int i = 0 ; i < 4; i++){ vertex(face2d[i].x * scale,face2d[i].y * scale,face2d[i].z * scale); } endShape(); line(0,0,0,nr.x*scale,nr.y*scale,nr.z*scale); //what do I do with this ? float c = cos(0), s = sin(0); float x2 = n.x*n.x,y2 = n.y*n.y,z2 = n.z*n.z; PMatrix3D m = new PMatrix3D(x2+(1-x2)*c, n.x*n.y*(1-c)-n.z*s, n.x*n.z*(1-c)+n.y*s, 0, n.x*n.y*(1-c)+n.z*s,y2+(1-y2)*c,n.y*n.z*(1-c)-n.x*s,0, n.x*n.y*(1-c)-n.y*s,n.x*n.z*(1-c)+n.x*s,z2-(1-z2)*c,0, 0,0,0,1); } Update Sorry if I'm getting annoying, but I don't seem to get it. Here's a bit of python using Blender's API: import Blender from Blender import * import math from math import sin,cos,radians,degrees def getRotMatrix(n): c = cos(0) s = sin(0) x2 = n.x*n.x y2 = n.y*n.y z2 = n.z*n.z l1 = x2+(1-x2)*c, n.x*n.y*(1-c)+n.z*s, n.x*n.y*(1-c)-n.y*s l2 = n.x*n.y*(1-c)-n.z*s,y2+(1-y2)*c,n.x*n.z*(1-c)+n.x*s l3 = n.x*n.z*(1-c)+n.y*s,n.y*n.z*(1-c)-n.x*s,z2-(1-z2)*c m = Mathutils.Matrix(l1,l2,l3) return m scn = Scene.GetCurrent() ob = scn.objects.active.getData(mesh=True)#access mesh out = ob.name+' ' #face0 f = ob.faces[0] n = f.v[0].no out += 'face: ' + str(f)+' ' out += 'normal: ' + str(n)+' ' m = getRotMatrix(n) m.invert() rvs = [] for v in range(0,len(f.v)): out += 'original vertex'+str(v)+': ' + str(f.v[v].co) + ' ' rvs.append(m*f.v[v].co) out += ' ' for v in range(0,len(rvs)): out += 'original vertex'+str(v)+': ' + str(rvs[v]) + ' ' f = open('out.txt','w') f.write(out) f.close All I do is get the current object, access the first face, get the normal, get the vertices, calculate the rotation matrix, invert it, then multiply it by each vertex. Finally I write a simple output. Here's the output for a default plane for which I rotated all the vertices manually by 30 degrees: Plane.008 face: [MFace (0 3 2 1) 0] normal: [0.000000, -0.499985, 0.866024](vector) original vertex0: [1.000000, 0.866025, 0.500000](vector) original vertex1: [-1.000000, 0.866026, 0.500000](vector) original vertex2: [-1.000000, -0.866025, -0.500000](vector) original vertex3: [1.000000, -0.866025, -0.500000](vector) rotated vertex0: [1.000000, 0.866025, 1.000011](vector) rotated vertex1: [-1.000000, 0.866026, 1.000012](vector) rotated vertex2: [-1.000000, -0.866025, -1.000012](vector) rotated vertex3: [1.000000, -0.866025, -1.000012](vector) Here's the first face of the famous Suzanne mesh: Suzanne.001 face: [MFace (46 0 2 44) 0] normal: [0.987976, -0.010102, 0.154088](vector) original vertex0: [0.468750, 0.242188, 0.757813](vector) original vertex1: [0.437500, 0.164063, 0.765625](vector) original vertex2: [0.500000, 0.093750, 0.687500](vector) original vertex3: [0.562500, 0.242188, 0.671875](vector) rotated vertex0: [0.468750, 0.242188, -0.795592](vector) rotated vertex1: [0.437500, 0.164063, -0.803794](vector) rotated vertex2: [0.500000, 0.093750, -0.721774](vector) rotated vertex3: [0.562500, 0.242188, -0.705370](vector) The vertices from the Plane.008 mesh are altered, the ones from Suzanne.001's mesh aren't. Shouldn't they ? Should I expect to get zeroes on one axis ? Once I got the rotation matrix from the normal vector, what is the rotation on x,y,z ? Note: 1. Blender's Matrix supports the * operator 2.In Blender's coordinate system Z point's up. It looks like a right handed system, rotated 90 degrees on X. Thanks
0
0
0
0
1
0
I'm using python, and I want a function that takes a string containing a mathematical expression of one variable (x) and returns a function that evaluates that expression using lambdas. Syntax should be such: f = f_of_x("sin(pi*x)/(1+x**2)") print f(0.5) 0.8 syntax should allow ( ) as well as [ ] and use standard operator precedence. Trig functions should have precedence lower than multiplication and higher than addition. Hence the string 'sin 2x + 1' would be equivalent to sin(2x)+1, though both are valid. This is for evaluating user input of algebraic and trigonometric expressions, so think math syntax not programming syntax. The list of supported functions should be easily extensible and the code should be clear and easy to understand. It's OK not to collapse constant expressions. The sample function here is incomplete. It takes a nested list representing the expression and generates an appropriate function. While somewhat easy to understand, even this seems ugly for python. import math def f_of_x(op): if (isinstance((op[0]), (int, long, float, complex)) ): return (lambda x:op[0]) elif op[0]=="pi": return lambda x: 3.14159265358979 elif op[0]=="e": return lambda x: 2.718281828459 elif op[0]=="x": return lambda x: x elif op[0]=="sin": return lambda x: math.sin(f_of_x(op[1])(x)) elif op[0]=="cos": return lambda x: math.cos(f_of_x(op[1])(x)) elif op[0]=="tan": return lambda x: math.tan(f_of_x(op[1])(x)) elif op[0]=="sqrt": return lambda x: math.sqrt(f_of_x(op[1])(x)) elif op[0]=="+": return lambda x: (f_of_x(op[1])(x))+(f_of_x(op[2])(x)) elif op[0]=="-": return lambda x: (f_of_x(op[1])(x))-(f_of_x(op[2])(x)) elif op[0]=="*": return lambda x: (f_of_x(op[1])(x))*(f_of_x(op[2])(x)) elif op[0]=="/": return lambda x: (f_of_x(op[1])(x))/(f_of_x(op[2])(x)) elif op[0]=="**": return lambda x: (f_of_x(op[1])(x))**(f_of_x(op[2])(x)) # should never get here with well formed input return def test(): # test function f(x) = sin(pi*x)/(1+x**2) s = ['/',['sin',['*',['pi'],['x']]],['+',[1],['**',['x'],[2]]]] f = f_of_x(s) for x in range(30): print " "*int(f(x*0.2)*30+10)+"x" As a general guideline, think of your solution as a tutorial on lambdas and parsers - not code golf. The sample code is just that, so write what you feel is clearest.
0
0
0
0
1
0
I need to run "mode" (which value occurs most frequently) on an array of singles in vb6. Is there a quick way do do this on large arrays?
0
0
0
0
1
0
I'm designing a realtime strategy wargame where the AI will be responsible for controlling a large number of units (possibly 1000+) on a large hexagonal map. A unit has a number of action points which can be expended on movement, attacking enemy units or various special actions (e.g. building new units). For example, a tank with 5 action points could spend 3 on movement then 2 in firing on an enemy within range. Different units have different costs for different actions etc. Some additional notes: The output of the AI is a "command" to any given unit Action points are allocated at the beginning of a time period, but may be spent at any point within the time period (this is to allow for realtime multiplayer games). Hence "do nothing and save action points for later" is a potentially valid tactic (e.g. a gun turret that cannot move waiting for an enemy to come within firing range) The game is updating in realtime, but the AI can get a consistent snapshot of the game state at any time (thanks to the game state being one of Clojure's persistent data structures) I'm not expecting "optimal" behaviour, just something that is not obviously stupid and provides reasonable fun/challenge to play against What can you recommend in terms of specific algorithms/approaches that would allow for the right balance between efficiency and reasonably intelligent behaviour?
0
1
0
0
0
0
I'm doing some queries that require a lot of joined rows have some of their fields added and multiplied together. I know it is sort of vague, but my question is which numeric data type is fastest for these types of operations? Will FLOAT be faster than DOUBLE since DOUBLE is 8 bytes, and FLOAT is 4? Will INT be faster than FLOAT (even if they are both 4 bytes)? Will DECIMAL be faster than FLOAT? Here's some more information: The problem I'm solving allows me the option to store "float" numbers as BIGINTEGER's... I can just multiply the number by 100000 before inserting them. I'd be willing to do this if BIGINT's math was faster than FLOAT's. Thanks.
0
0
0
0
1
0
The following unstructured text has three distinct themes -- Stallone, Philadelphia and the American Revolution. But which algorithm or technique would you use to separate this content into distinct paragraphs? Classifiers won't work in this situation. I also tried to use Jaccard Similarity analyzer to find distance between successive sentences and tried to group successive sentences into one paragraph if the distance between them was less than a given value. Is there a better method? This is my text sample: Sylvester Gardenzio Stallone , nicknamed Sly Stallone, is an American actor, filmmaker and screenwriter. Stallone is known for his machismo and Hollywood action roles. Stallone's film Rocky was inducted into the National Film Registry as well as having its film props placed in the Smithsonian Museum. Stallone's use of the front entrance to the Philadelphia Museum of Art in the Rocky series led the area to be nicknamed the Rocky Steps.A commercial, educational, and cultural center, Philadelphia was once the second-largest city in the British Empire (after London), and the social and geographical center of the original 13 American colonies. It was a centerpiece of early American history, host to many of the ideas and actions that gave birth to the American Revolution and independence.The American Revolution was the political upheaval during the last half of the 18th century in which thirteen colonies in North America joined together to break free from the British Empire, combining to become the United States of America. They first rejected the authority of the Parliament of Great Britain to govern them from overseas without representation, and then expelled all royal officials. By 1774 each colony had established a Provincial Congress, or an equivalent governmental institution, to form individual self-governing states.
0
1
0
0
0
0
Over on FSHUB, LethalLavaLand said, Let me plot my values! So the question is, how can I plot a data series in F# using built-in .NET 4.0 controls?
0
0
0
0
1
0
I'm trying to calculate triangles base on the Area and the angles. If Angle-B is 90° then the formula works, but in my case, the angle can be from 0.1° to 179.8°. The formula assumes that the angle is 90, so I was thinking that there might be something that is hidden that could work for very angle. Here is the formula: The formula in code would be: Height = sqrt((2 * Area) / (tan(Angle-A))); I'm looking for the second half of the formula. Would the next part of the formula be something like this: cos(sin(AngleB))
0
0
0
0
1
0
I'm looking for a packing algorithm which will reduce a regular polygon into rectangles and right triangles. The algorithm should attempt to use as few such shapes as possible and should be relatively easy to implement (given the difficulty of the challenge). If possible, the answer to this question should explain the general heuristics used in the suggested algorithm.
0
0
0
0
1
0
I'm trying to find a root of a function that may be immediately before it begins having only imaginary values. (Specifically, it's the intersection of a line and a half-circle.) Obviously neither Brent's nor the bisection method will work; neither will Newton's method. Is there a less-obvious one that will?
0
0
0
0
1
0
Given n squares with edge length l, how can I determine the minimum radius r of the circle so that I can distribute all squares evenly along the perimeter of the circle without them overlapping? (Constraint: the first square will always be positioned at 12 o'clock.) Followup question: how can I place n identical rectangles with height h and width w? (source: n3rd.org)
0
0
0
0
1
0
a=(0-100) when x=0, a should be 0 when x=100, a should be 100 the data needs to bell curve towards the 100 mark, so that once x passes 100 a will remain at 100 and not go over. Explanation and application follows: We have a number of rows of data that are counted as good, bad or questionable. If a row is bad we count it as full value (1.0) against the total. so 100 rows with o1 bad = 99% success if a row is questionable, we count it as a percentage of 1 against (maybe .75) so 100 rows with 1 questionable results in 99.25% success I would like to build in a factor to apply to that value (bad affect or questionable affect) that would reduce it to zero affect (in either case) if there is only 1 row of data. so.. some thing like: 1 row with 1 bad or questionable = 100% success (no matter the questionable affect) 2 rows with one bad would yield nearly 100% success 10 rows with one bad might yield a 99% success rate 50 rows with 1 bad would yield 99.5% 100 rows with one bad would yield 99% similar affect to questionable results This factor that I am attempting to derive would be applied to the affect variable for each of bad and questionable affects. The factor also will have no implication on the affect once it reaches a certain value, in the above sample 100. it will always start at 0. Thanks for any assistance. -Scott
0
0
0
0
1
0
I need to limit an angle so it fits into a segment. I have drawn and links to a diagram below to better describe what I am after. I am trying to calculate this for a computer program, where I have an angle (slope), and a point (the mouse pointer). The distance does not matter to me, just the angles. If the point is within b1 (green area) then that's fine. But if the point is within b2 or b3 (red or orange) areas, then the angle should snap back to the limit of the green area (along the line s). (source: adamharte.com) The main problem I am having in figuring this out, is snapping the angle to the correct side e.g. If the point is in the red area, then the angle should snap to the angle s on the red side and vice versa. I am also having trouble because s could be any angle, so I am being tripped up because I can't just do something like this: if a(radians) is greater than s(radians) then set a to the value of s or I will get errors when the angle goes between zero and 2Pi. So How would I work this out? Do I have to rotate everything back to a zero point or something then put it back when I have made my calculations? Thanks for reading my questing.
0
0
0
0
1
0
I want to classify using libsvm. I have 9 training sets , each set has 144000 labelled instances , each instance having a variable number of features. It is taking about 12 hours to train one set ( ./svm-train with probability estimates ). As i dont have much time , I would like to run more than one set at a time. I'm not sure if i can do this.. Can i run all 9 processes simultaneously in different terminals ? ./svm-train -b 1 feat1.txt ./svm-train -b 1 feat2.txt . . . ./svm-train -b 1 feat9.txt ( i'm using fedora core 5 )
0
0
0
1
0
0
while playing to this game I wondered how an AI controlling either the detectives either the criminal could work. For lazy people the aim of the game is simple: the board game is an undirected graphs that has 4 kinds of edges (that can also overlap for same pair or vertices), each kind is a type of transport that requires a specific kind of ticket detectives have a bunch of tickets to move around this graph, one move per turn (which means from a node to another node). The criminal can do the same set of moves (plus 3 exclusive paths) but with no limits on tickes the criminal is usually hidden to detectives but it has to show up himself in 5 specific turns (and then hide again) if detectives are able to catch him (one of them must occupy the same cell of the criminal) before 24 moves then they win, otherwise the criminal wins the criminal has to show which ticket he uses each turn but he also has 1 black ticket per detective (let's assume 5) that can be used to vanify this thing the criminal also has two 2x tickets that allow him to use two tickets (and so two movements) in the same turn I can think effectively about an AI for the criminal that it would be just a minmax tree that tries to choose movements that maximize the number of moves needed by detectives to reach him (it seems to be a good metric) but I cannot think anything enough cool for detectives which should cooperate and try to guess where the criminal can be by looking at tickets it uses. It's just for fun but do you now any cool ideas to work out something quite clever?
0
1
0
0
0
0
I'd like to create a function which will generate a 3 char key string after each loop. There are 26 chars in the alphabet and I'd like to generate totally unique 3 char keys (A-Z). The output would be 17,576 unique 3 char keys (A-Z) - not case sensitive. Can anyone give me an idea on how to create a more elegant function without randomly generating keys and checking for duplicate keys? Is it possible Thank you.
0
0
0
0
1
0
(Apologies in advance. My math skills and powers of description seem to have left me for the moment) Imagine a cube on screen with a two sets of controls. One set of controls to rotate the cube side to side (aka yaw or Y or even Z depending on one's mathematical leanings) and another set of controls to rotate up and down (aka pitch or X). What I would like to do is make it so that the two set sof controls always rotate the cube in relation to the viewer / screen irrespective of how the cube is currently rotated. A regular combination of either matrix or quaternion based rotations doesn't achieve this effect because the rotations get applied in a serial fashion (with each rotation "starting" from where the previous one left off). e.g. With the psuedo code of combinatedRotation = RotateYaw(90) * RotatePitch(45) will give me a cube that appears to be "rolling" to one side because the Pitch rotation has been rotated as well. (or for a more dramatic example RotateYaw(180) * RotatePitch(45) will produce a cube where it appears the the pitch is working in reverse to the screen) Can somebody either point me to or supply the correct way to make the two rotations independant from each other in effect so that irrespective of how the cube is currently rotated Yaw and Pitch work "as expected" in relation to the on screen controls?
0
0
0
0
1
0
I am using a generic approach to receiving a single row from any Oracle table and displaying it in a datagridview, using the code below. But, if the table contains a column of float type and the value has a large number of decimal places, I get "Arithmetic operation resulted in an overflow" at the line: MyReader.GetValues(objCells); oCmd.CommandText = "OTCMIADM.OTCMI_GUI.GET_ROW"; oCmd.CommandType = CommandType.StoredProcedure; oCmd.Parameters.Add("PI_TABLE_NAME", OracleDbType.Varchar2, 40).Value = cmbStagingTables.SelectedItem; oCmd.Parameters.Add("PI_ROWID", OracleDbType.Varchar2, 40).Value = txtRowID.Text; oCmd.Parameters.Add(new OracleParameter("PIO_CURSOR", OracleDbType.RefCursor)).Direction = ParameterDirection.Output; oCmd.ExecuteNonQuery(); // clear the datagrid in preperation for loading dgvStagingTable.Columns.Clear(); dgvStagingTable.Rows.Clear(); using (OracleDataReader MyReader = oCmd.ExecuteReader()) { int ColumnCount = MyReader.FieldCount; // add the column headers DataGridViewColumn[] columns = new DataGridViewColumn[ColumnCount]; for (int i = 0; i < columns.Length; ++i) { DataGridViewColumn column = new DataGridViewTextBoxColumn(); column.FillWeight = 1; column.HeaderText = MyReader.GetName(i); column.Name = MyReader.GetName(i); columns[i] = column; } dgvStagingTable.Columns.AddRange(columns); // get the data and add the row while (MyReader.Read()) { //get all row values into an array object[] objCells = new object[ColumnCount]; MyReader.GetValues(objCells); //add array as a row to grid dgvStagingTable.Rows.Add(objCells); } } The stack trace shows: at Oracle.DataAccess.Types.DecimalConv.GetDecimal(IntPtr numCtx) at Oracle.DataAccess.Client.OracleDataReader.GetDecimal(Int32 i) at Oracle.DataAccess.Client.OracleDataReader.GetValue(Int32 i) at Oracle.DataAccess.Client.OracleDataReader.GetValues(Object[] values) So I can see why it's causing an error (it's assuming a decimal conversion); but how do I get round this? I tried explicitly setting the type of the column before loading the data with: dgvStagingTable.Columns["TR_THROUGHPUT_TIME_NO"].ValueType = typeof(string); and several other typeofs, but nothing made any difference. Any help appreciated.
0
0
0
0
1
0
I have a large collection of documents that already have their TF-IDF computed. I'm getting ready to add some more documents to the collection, and I am wondering if there is a way to add TF-IDF scores to the new documents without re-processing the entire database?
0
1
0
1
0
0
I'm looking for a packing algorithm which will reduce an irregular polygon into rectangles and right triangles. The algorithm should attempt to use as few such shapes as possible and should be relatively easy to implement (given the difficulty of the challenge). It should also prefer rectangles over triangles where possible. If possible, the answer to this question should explain the general heuristics used in the suggested algorithm. This should run in deterministic time for irregular polygons with less than 100 vertices. The goal is to produce a "sensible" breakdown of the irregular polygon for a layman. The first heuristic applied to the solution will determine if the polygon is regular or irregular. In the case of a regular polygon, we will use the approach outlined in my similar post about regular polys: Efficient Packing Algorithm for Regular Polygons alt text http://img401.imageshack.us/img401/6551/samplebj.jpg
0
0
0
0
1
0
I have a camera mounted on a tripod its motion is restricted to pan and tilt rotation. It is looking at dot that is at a known location directly in front of the camera. If the camera looks at the dot and gets the 2d coordinate of it, is it possible to deduce the camera's rotation so that I can overlay some 3d models properly aligned to the scene. I was thinking that it could be solved by reversing the formula that you would use to plot the 2d point you could derive a formula to take a 2d point and give back the camera rotation. I am thinking that the 2d plot would be something like Dot's 3d Target World Position * Camera Position Matrix * Camera Rotation Matrix * Perspective Matrix = 2d point Is it possible to derive the camera's rotation from the 2d point given that the camera and dot's position are known as well as the perspective matrix (I am assuming I should be able to guess at this and get close by tweaking the field of vision value)?
0
0
0
0
1
0
I have seen programmers "battling" it out with really complex mathematical problems in their codes, particularly in the fields of game programming, physics programming, graphics programming, etc. I am a web developer, and I wonder if there are math concepts out there that I can use for web programming. I started web programming a year and 2 months ago, and all I have dealt with were complex analysis of systems, database queries, user interface designs, simple data structures, complex data manipulation and interpretation (regexes, parsing, etc) but I have not (yet) found a need for complex math. So to repeat the question, are there mathematical concepts out there that can leverage my web development skills? If there are, what scenarios are do they come as an advantage or indispensable?
0
0
0
0
1
0
I want to use math functions for data mining and analytics purpose. I need an opinion about a library that I can use for this purpose with java. Do you have any recommendations?
0
0
0
0
1
0
According to wiki shifts can be used to calculate powers of 2: A left arithmetic shift by n is equivalent to multiplying by 2^n (provided the value does not overflow), while a right arithmetic shift by n of a two's complement value is equivalent to dividing by 2^n and rounding toward negative infinity. I was always wondering if any other bitwise operators (~,|,&,^) make any mathematical sense when applied to base-10? I understand how they work, but do results of such operations can be used to calculate anything useful in decimal world?
0
0
0
0
1
0
I am planning to implement spam filter using Naive Bayesian classification model. Online I see a lot of info on Naive Bayesian classification, but the problem is its a lot of mathematical stuff, than clearly stating how its done. And the problem is I am more of a programmer than a mathematician (yes I had learnt Probability and Bayesian theorem back in school, but out of touch for a long long time, and I don't have luxury of learning it now (Have nearly 3 weeks to come-up with a working prototype)). So if someone can explain or point me to location where its explained for programmers than a mathematician, it would be a great help. PS: By the way I have to implement it in C, if you want to know. :( Regards, Microkernel
0
0
0
0
1
0
Below, the result1 and result2 variable values are reporting different values depending upon whether or not you compile the code with -g or with -O on GCC 4.2.1 and on GCC 3.2.0 (and I have not tried more recent GCC versions): double double_identity(double in_double) { return in_double; } ... double result1 = ceil(log(32.0) / log(2.0)); std::cout << __FILE__ << ":" << __LINE__ << ":" << "result1==" << result1 << std::endl; double result2 = ceil(double_identity(log(32.0) / log(2.0))); std::cout << __FILE__ << ":" << __LINE__ << ":" << "result2==" << result2 << std::endl; result1 and result2 == 5 only when compiling using -g, but if instead I compile with -O I get result1 == 6 and result2 == 5. This seems like a difference in how optimization is being done by the compiler, or something to do with IEEE floating point representation internally, but I am curious as to exactly how this difference occurs. I'm hoping to avoid looking at the assembler if at all possible. The above was compiled in C++, but I presume the same would hold if it was converted to ANSI-C code using printfs. The above discrepancy occurs on 32-bit Linux, but not on 64-bit Linux. Thanks bg
0
0
0
0
1
0
What is the opposite of the Math.tan(double x) function of java? I know that Tan(X) = oppositeSideLength/AdjacentSideLength but I have the opposite and adjacent sides so I want to do the opposite operation. ie: x = Tan^-1(oppositeSideLenght/AdjacentSideLength) (that is how I would enter it in a calculator. I just looked in the Math class and I know that there is: Math.atan( Math.atan2 but I don't think that either of these is what I am looking for.
0
0
0
0
1
0
I bought a blank DVD to record my favorite TV show. It came with 20 digit stickers. 2 of each of '0'-'9'. I thought it would be a good idea to numerically label my new DVD collection. I taped the '1' sticker on my first recorded DVD and put the 19 leftover stickers in a drawer. The next day I bought another blank DVD (receiving 20 new stickers with it) and after recording the show I labeled it '2'. And then I started wondering: when will the stickers run out and I will no longer be able to label a DVD? A few lines of Python, no? Can you provide code that solves this problem with a reasonable run-time? Edit: The brute force will simply take too long to run. Please improve your algorithm so your code will return the right answer in, say, a minute? Extra credit: What if the DVDs came with 3 stickers of each digit?
0
0
0
0
1
0
I would like to know of open source tools (for java/python) which could help me extract semantic & stylistic features from text. Examples of semantic features would be adjective-noun ratio, a particular sequence of part-of-speech tags (adjective followed by a noun: adj|nn) etc. Examples of stylistic features would be number of unique words, number of pronouns etc. Currently, I know only of Word to Web Tools which converts a block of text into the rudimentary vector space model. I am aware of few text-mining packages like GATE, NLTK , Rapid Miner, Mallet and MinorThird . However, I couldn't find any mechanism to suit my task. Regards, --Denzil
0
0
0
1
0
0
I'm searching ways to identify scores, when someone is playing i.e. guitar. How can I manage that? I've heard that midi stores music data as musical scores. I wonder if it's a good solution.
0
1
0
0
0
0
It seems that simple comparison signs >,>= and their reverse components can evaluate if a certain variable is a number or not. Example $whatami='beast'; ($whatami<0)?echo 'NaN':echo 'is numeric!'; Are there cases where is_numeric() usage is necessary for positive values (number >0)? It seems that using comparison signs above would determine if the variable is numeric..
0
0
0
0
1
0
Is anyone aware of a hierarchical task network planner implemented in Python or Java? I've found a few open source systems, but they're all seemingly dead projects and haven't been maintained in years.
0
1
0
1
0
0
A continued fraction is a series of divisions of this kind: depth 1 1+1/s depth 2 1+1/(1+1/s) depth 3 1+1/(1+1/(1+1/s)) . . . . . . . . . The depth is an integer, but s is a floating point number. What would be an optimal algorithm (performance-wise) to calculate the result for such a fraction with large depth?
0
0
0
0
1
0
How would you assign objective certainties to statements asserted by different users in an ontology? For example, consider User A asserts "Bob's hat is blue" while User B asserts "Bob's hat is red". How would you determine if: User A and User B are referring to different people named Bob, and may or may not be correct. Both users are referring to the same person, but User A is right and User B is mistaken (or vice versa). Both users are referring to the same person, but User A is right and User B is lying (or vice versa). Both users are referring to the same person, and both uses are either mistaken or lying. The main difficulty I see is the ontology doesn't have any way to obtain first-hand data (e.g. it can't ask Bob what color his hat is). I realize there's probably no entirely objective way to resolve this. Are there any heuristics that could be employed? Does this problem have a formal name?
0
1
0
1
0
0
I read over the wikipedia article, but it seems to be beyond my comprehension. It says it's for optimization, but how is it different than any other method for optimizing things? An answer that introduces me to linear programming so I can begin diving into some less beginner-accessible material would be most helpful.
0
0
0
0
1
0
I'am trying to measure the performance of a computer vision program that tries to detect objects in video. I have 3 different versions of the program which have different parameters. I've benchmarked each of this versions and got 3 pairs of (False positives percent, False negative percent). Now i want to compare the versions with each other and then I wonder if it makes sense to combine false positives and false negatives into a single value and use that to do the comparation. for example, take the equation falsePositives/falseNegatives and see which is smaller.
0
0
0
1
0
0
I have the following code: typedef __int64 BIG_INT; typedef double CUT_TYPE; #define CUT_IT(amount, percent) (amount * percent) void main() { CUT_TYPE cut_percent = 1; BIG_INT bintOriginal = 0x1FFFFFFFFFFFFFF; BIG_INT bintAfter = CUT_IT(bintOriginal, cut_percent); } bintAfter's value after the calculation is 144115188075855872 instead of 144115188075855871 (see the "2" in the end, instead of "1"??). On smaller values such as 0xFFFFFFFFFFFFF I get the correct result. How do I get it to work, on 32bit app? What do I have to take in account? My aim is to cut a certain percentage of a very big number. I use VC++ 2008, Vista.
0
0
0
0
1
0
I am new to c, and the following is giving me some grief: int i,j,ll,k; double ddim,ddip,ddjm,ddjp,ddlm,ddlp; for(i=1; i<(mx-1); i++){ for(j=1; j<(my-1); j++){ for(ll=1; ll<(mz-1); ll++){ ddim=0.5*k ddip=0.5*k ddjm=0.5*k ddjp=0.5*k ddlm=0.5*k ddlp=0.5*k Wijl(i,j,ll) = ((1.0/h_x)*(ddip) \ ((1.0/h_x)*(ddim)) \ ((1.0/h_y)*(ddjp)) \ ((1.0/h_y)*(ddjm)) \ ((1.0/h_z)*(ddlp)) \ ((1.0/h_z)*(ddlm)) ; } } } I then compile this with gcc using python and scipy, passing it everything that is not initialized, but I know the problem is in the 1.0/h_x part of the code. If I compile basic c statements using python/gcc it works, so I am not having a python/gcc issue. The error I am getting is: "error: ambiguous overload for 'operator/' in '1.0e+0 / h_x' It seems like it is trying to do assignment overloading, and all I want to do is division! Any help would be greatly appreciated! :) Thanks, Tyler
0
0
0
0
1
0
I have a rectangle say (150, 200, 25,25) and x- axis up to 800 and y-axis upto 650. Now like to increase the value of x and y axis by 100. The rectangle value also increase according to x and y axis. say my rectangle are in the shaded place. now i increase the x and y axis. the shaded position also increases. the rectangle value also need to increase so it placed in that shaded place as before. How can i achieve this... Thanks in advance....
0
0
0
0
1
0
My problem is conceptually similar to solving anagrams, except I can't just use a dictionary lookup. I am trying to find plausible words rather than real words. I have created an N-gram model (for now, N=2) based on the letters in a bunch of text. Now, given a random sequence of letters, I would like to permute them into the most likely sequence according to the transition probabilities. I thought I would need the Viterbi algorithm when I started this, but as I look deeper, the Viterbi algorithm optimizes a sequence of hidden random variables based on the observed output. I am trying to optimize the output sequence. Is there a well-known algorithm for this that I can read about? Or am I on the right track with Viterbi and I'm just not seeing how to apply it? Update I have added a bounty to ask for more insight into this problem. (Analysis explaining why an efficient approach isn't possible, other heuristics/approximations besides simulated annealing, etc.)
0
0
0
1
0
0
I'm working on opengl project. I set up perspective projection and render a transformed rectangle (rotated, scaled) How i can calculate rectangle's bounding box (rectangle position,size) Thank you
0
0
0
0
1
0
Matrix math library that is good to use alongside OpenGL to keep track of primitive co-ordinates. Does such a thing exist? Is this the best way to track my objects for use in collision detection?
0
0
0
0
1
0
I am searching in Wordnet for synonyms for a big list of words. The way I have it done it, when some word has more than one synonym, the results are returned in alphabetical order. What I need is to have them ordered by their probability of occurrence, and I would take just the top 1 synonym. I have used the prolog wordnet database and Syns2Index to convert it into Lucene type index for querying synonyms. Is there a way to get them ordered by their probabilities in this way, or I should use another approach? Speed not important, this synonym lookup will not be done online.
0
1
0
0
0
0
I have a 'large' set of line delimited full sentences that I'm processing with Hadoop. I've developed a mapper that applies some of my favorite NLP techniques to it. There are several different techniques that I'm mapping over the original set of sentences, and my goal during the reducing phase is to collect these results into groups such that all members in a group share the same original sentence. I feel that using the entire sentence as a key is a bad idea. I felt that generating some hash value of the sentence may not work because of a limited number of keys (unjustified belief). Can anyone recommend the best idea/practice for generating unique keys for each sentence? Ideally, I would like to preserve order. However, this isn't a main requirement. Aντίο,
0
1
0
0
0
0
Are there any tools available for generating RDF from natural language? A list of RDFizers compiled by the SIMILE project only mentions one, the Monrai Cypher. Unfortunately, it seems to have been a proprietary tool developed by Monrai Technologies, which has since disappeared, and I can't find any download links. Has anyone seen anything similar?
0
1
0
1
0
0
Using PyClips, I'm trying to build rules in Clips that dynamically retrieve data from the Python interpreter. To do this, I register an external function as outlined in the manual. The code below is a toy example of the problem. I'm doing this because I have an application with a large corpus of data, in the form of a SQL database, which I want to reason with using Clips. However, I don't want to waste time converting all this data into Clips assertions, if I can simply "plug" Clips directly into Python's namespace. However, when I try to create the rule, I get an error. What am I doing wrong? import clips #user = True #def py_getvar(k): # return globals().get(k) def py_getvar(k): return True if globals.get(k) else clips.Symbol('FALSE') clips.RegisterPythonFunction(py_getvar) print clips.Eval("(python-call py_getvar user)") # Outputs "nil" # If globals().get('user') is not None: assert something clips.BuildRule("user-rule", "(neq (python-call py_getvar user) nil)", "(assert (user-present))", "the user rule") #clips.BuildRule("user-rule", "(python-call py_getvar user)", "(assert (user-present))", "the user rule") clips.Run() clips.PrintFacts()
0
0
0
1
0
0
I'm confusing myself terribly grasping the concept of plotting on a 3D plane, if I'm looking down the -Z axis, to put an objectinfront of me I just make the Z value Negative and to put it behind I just make it positive.. but.. how do I Put objects to my left or right? Sorry, I realise this is a stupid question but none the less it's confusing me Example I'm drawing a square at (-3,-2,10; -3, 2, 10; 3,-2, 10; 3, 2, 10) how would I draw something to its right or left hand side?
0
0
0
0
1
0
I have question that comes from a algorithms book I'm reading and I am stumped on how to solve it (it's been a long time since I've done log or exponent math). The problem is as follows: Suppose we are comparing implementations of insertion sort and merge sort on the same machine. For inputs of size n, insertion sort runs in 8n^2 steps, while merge sort runs in 64n log n steps. For which values of n does insertion sort beat merge sort? Log is base 2. I've started out trying to solve for equality, but get stuck around n = 8 log n. I would like the answer to discuss how to solve this mathematically (brute force with excel not admissible sorry ;) ). Any links to the description of log math would be very helpful in my understanding your answer as well. Thank you in advance!
0
0
0
0
1
0
I am in the process of writing a fairly long monograph on a computer science topic. However, I usually find myself in a position of having to write some computer science concept in mathematical terms, and it is difficult to me. For instance, say I want to write a for-loop or a void function. I do most of the time go to my Knuth or Cormen or Sedgewick, but they are not enough now. Is there a "manual" or some text I can take as example to translate computer science into mathematics? Edit Let me be more specific (thanks, Uri). What I mean is: For example, I have a function that is void, and it returns a random string of length n. This caused my curiosity, I don't even know how to represent void function in in math... but again, this is just an example.
0
0
0
0
1
0
As mentioned above. I give one example, let's say all the test values are less than 1 but greater than 0. 0.12 (precision: 3, scale:2) 0.345 (precision: 4, scale:3) 0.6789 (precision: 5, scale:4) how do i convert those value without hard-coding the scale and precision value. 0.12 -> 12 0.345 -> 345 0.6789 -> 6789 for 0.1 and 0.01 and 0.001 should get 1 (i know this i bad idea but i have been given sets of business rules of the software) i prefer solution in java but if there is a math algorithm it is better. thanks.
0
0
0
0
1
0
I have a function that takes a floating point number and returns a floating point number. It can be assumed that if you were to graph the output of this function it would be 'n' shaped, ie. there would be a single maximum point, and no other points on the function with a zero slope. We also know that input value that yields this maximum output will lie between two known points, perhaps 0.0 and 1.0. I need to efficiently find the input value that yields the maximum output value to some degree of approximation, without doing an exhaustive search. I'm looking for something similar to Newton's Method which finds the roots of a function, but since my function is opaque I can't get its derivative.
0
0
0
0
1
0
I have written some page turning software simulating a magazine. Currently the speed of the page turning is linear, and I want to make it more realistic with acceleration and deceleration. At the start of the animation it should be slow, half way through it should have reached max speed, then it returns to a slow speed by the end of the animation. Someone I knew told me it can be done if you know what percentage of the animation you are through, using sine or something similar! So given a percentage representing how far through the animation you are, how can you set the speed? Answers in pseduo or javascript welcome :) function speed(percentageThroughAnimation) { return ????? }
0
0
0
0
1
0
I have a percentage, it ranges from 50% to 0%. I need the values to be mirrored, so: 0% now equals 50% 1% = 49% 25% = 25% 48% = 2% 50% = 0% etc. Thanks for any help!
0
0
0
0
1
0
I'm writing an AI for a card game and after some testing I've discovered that using MTD(f) on my alpha beta algorithm - a series of zero-window searches - is faster than just using alpha-beta by itself. The MTD(f) algorithm is described well here http://people.csail.mit.edu/plaat/mtdf.html The problem I have is that for each pass in the MTD(f) search (for each guess) I don't reuse any of the previous positions I have stored even though the write up on the link suggests that I should (in fact clearing the table between iterations speeds up the algorithm). My problem is that when I store a position and a value in my transposition table I also store the alpha and beta values for which it is valid. Therefore a second pass through the tree with a different guess (and therefore alpha and beta) can't possibly reuse any information. Is this what is to be expected or am I missing something fundamental here? For instance if for alpha=3 beta=4 we come to a result of 7 (obviously a cut-off) should I store that in the table as valid for alpha=3 to beta=6? Or beta=7?
0
1
0
0
0
0
I need an algorithm that identifies all possible combinations of a set of numbers that sum to some other number. For example, given the set {2,3,4,7}, I need to know all possible subsets that sum to x. If x == 12, the answer is {2,3,7}; if x ==7 the answer is {{3,4},{7}} (ie, two possible answers); and if x==8 there is no answer. Note that, as these example imply, numbers in the set cannot be reused. This question was asked on this site a couple years ago but the answer is in C# and I need to do it in Perl and don't know enough to translate the answer. I know that this problem is hard (see other post for discussion), but I just need a brute-force solution because I am dealing with fairly small sets.
0
0
0
0
1
0
It has been discussed on this site before about the relationship between math and programming, and whether one is a subset of the other, etc. In my recent study of programming, I've found myself more and more wishing I was better at math. You all know the scenario when programming books start to generalize something in a math way ("Therefore, we may say that for all <some single letter>, <lots of letters>"). My eyes glaze over in such situations. I know that that is mostly due to me being stupid, but it seems that if I could just improve my higher math skills, maybe I could get more out of such things. Major question: Is math indeed something one can "get better at," or is your brain kinda either wired for it or not? Important follow-up question: If the answer to the above is yes, then what are some ways to go about it?
0
0
0
0
1
0
I have two variables : count, which is a number of my filtered objects, and constant value per_page. I want to divide count by per_page and get integer value but I no matter what I try - I'm getting 0 or 0.0 : >>> count = friends.count() >>> print count 1 >>> per_page = 2 >>> print per_page 2 >>> pages = math.ceil(count/per_pages) >>> print pages 0.0 >>> pages = float(count/per_pages) >>> print pages 0.0 What am I doing wrong, and why math.ceil gives float number instead of int ?
0
0
0
0
1
0
I'm trying to write a method that interpolates from 0 to x (position of an object in one dimension) over time using acceleration at the beginning and deceleration at the end (ease out / ease in) with the only constraints that the total time is provided, as well as the duration of the acceleration and deceleration. the motion should replicate the inertia effect and I'm considering a Hermite curve for the non-linear portions. double Interpolate( double timeToAccel, double timeCruising, double timeToDecel, double finalPosition, double currentTime) { //... } Can someone point me out to a portion of code that does that? I don't know how to integrate the Hermite curve, hence don't know how much I'll move in the accelerating portion or in the decelerating portion, and in turn I can't figure out what will be the speed in the linear portion. Thanks. Some reference to illustrate my question. Edit: start and end speeds are null, and the current time is also part of the parameters in the method, I've updated the signature. basically the idea is to imagine a move at constant speed on a distance d, this gives a total duration. Then we add the acceleration and deceleration phases, while maintaining the same duration, hence we have an unknown new cruise speed to determinate (because we move less in the Hermite phases than in the linear phases they have replaced). Maybe the amount of move lost in the Hermite phases, compared to a linear move of the same duration is the ratio between the top and bottom area in the curves, just an idea from a non expert. Edit: Roman and Bob10 have provided full working solutions. I implemented the code from Roman. Thanks to you both, guys! I appreciate your perfect support and your detailed solutions, you saved me long searches and trials.
0
0
0
0
1
0
I'm looking for a method to generate a pseudorandom stream with a somewhat odd property - I want clumps of nearby numbers. The tricky part is, I can only keep a limited amount of state no matter how large the range is. There are algorithms that give a sequence of results with minimal state (linear congruence?) Clumping means that there's a higher probability that the next number will be close rather than far. Example of a desirable sequence (mod 10): 1 3 9 8 2 7 5 6 4 I suspect this would be more obvious with a larger stream, but difficult to enter by hand. Update: I don't understand why it's impossible, but yes, I am looking for, as Welbog summarized: Non-repeating Non-Tracking "Clumped"
0
0
0
0
1
0
I have had this problem for a while, still trying to work on a solution. What is the best possible method for evenly distributing items in a list, with a low discrepancy? Say we have a list or elements in an array: Red, Red, Red, Red, Red, Blue, Blue, Blue, Green, Green, Green, Yellow So ideally the output would produce something like: Red, Blue, Red, Green, Red, Yellow, Blue, Red, Green, Red, Blue, Green. Where each instance is "as far away" from another instance of itself as possible... When, I first attempted trying to solve this problem, I must admit I was naive, so I just used some form of seeded random number to shuffle the list, but this leads to clumping of instances. A suggestion was start with the item with the highest frequency, so red will be put in position n*12/5 for n from 0 to 4 inclusive. Then place the next most repeated element (Blue) in positions n*12/3 + 1 for n from 0 to 2 inclusive. If something is already placed there, just put it in the next empty spot. etc etc. However, when jotting it out on paper this doesn't work in all circumstances, Say the list is only Red, Red, Red, Red, Red, Blue It will fail. Where either option has three same-color adjacencies Red, Red, Blue, Red, Red, Red Red, Red, Red, Blue, Red, Red So please, any ideas, or implementations how to do this would be awesome. If it matters i'm working on objective-c, but right now all I care about is the methodology how to do it.
0
0
0
0
1
0
PHP converts a large number to floating point which I need in "long" format to pass to a soap xml api. ((round(time()/(60*15))*60*15)+(30*60))*1000 This gives the result: 1.28E+12 Whereas, what I need is: "1280495700000" in order to pass to the api
0
0
0
0
1
0
I know this sounds like a homework assignment, but it isn't. Lately I've been interested in algorithms used to perform certain mathematical operations, such as sine, square root, etc. At the moment, I'm trying to write the Babylonian method of computing square roots in C#. So far, I have this: public static double SquareRoot(double x) { if (x == 0) return 0; double r = x / 2; // this is inefficient, but I can't find a better way // to get a close estimate for the starting value of r double last = 0; int maxIters = 100; for (int i = 0; i < maxIters; i++) { r = (r + x / r) / 2; if (r == last) break; last = r; } return r; } It works just fine and produces the exact same answer as the .NET Framework's Math.Sqrt() method every time. As you can probably guess, though, it's slower than the native method (by around 800 ticks). I know this particular method will never be faster than the native method, but I'm just wondering if there are any optimizations I can make. The only optimization I saw immediately was the fact that the calculation would run 100 times, even after the answer had already been determined (at which point, r would always be the same value). So, I added a quick check to see if the newly calculated value is the same as the previously calculated value and break out of the loop. Unfortunately, it didn't make much of a difference in speed, but just seemed like the right thing to do. And before you say "Why not just use Math.Sqrt() instead?"... I'm doing this as a learning exercise and do not intend to actually use this method in any production code.
0
0
0
0
1
0
I'm currently implementing a software that measures certain values over time. The user may choose to measure the value 100 times over a duration of 28 days. (Just to give an example) Linear distribution is not a problem, but I am currently trying to get a logarithmical distribution of the points over the time span. The straight-forward implementation would be to iterate over the points and thus I'll need an exponential function. (I've gotten this far!) My current algorithm (C#) is as follows: long tRelativeLocation = 0; double tValue; double tBase = PhaseTimeSpan.Ticks; int tLastPointMinute = 0; TimeSpan tSpan; for (int i = 0; i < NumberOfPoints; i++) { tValue = Math.Log(i + 1, NumberOfPoints); tValue = Math.Pow(tBase, tValue); tRelativeLocation = (long)tValue; tSpan = new TimeSpan(tRelativeLocation); tCurrentPoint = new DefaultMeasuringPointTemplate(tRelativeLocation); tPoints.Add(tCurrentPoint); } this gives me a rather "good" result for 28 days and 100 points. The first 11 points are all at 0 seconds, 12th point at 1 sec, 20th at 50 sec, 50th at 390 min, 95th at 28605 mins 99 th at 37697 mins (which makes 43 hours to the last point) My question is: Does anybody out there have a good idea how to get the first 20-30 points further apart from each other, maybe getting the last 20-30 a bit closer together? I understand that I will eventually have to add some algorithm that sets the first points apart by at least one minute or so, because I won't be able to get that kind of behaviour into a strictly mathematical algorithm. Something like this: if (((int)tSpan.TotalMinutes) <= tLastPointMinute) { tSpan = new TimeSpan((tLastPointMinute +1) * 600000000L); tRelativeLocation = tSpan.Ticks; tLastPointMinute = (int)tSpan.TotalMinutes; } However, I'd like to get a slightly better distribution overall. Any cool ideas from you math cracks out there would be greatly appreciated!
0
0
0
0
1
0
I am trying to have a regular expression split on equations like 1.5+4.2*(5+2) with operators - + * / so the output would be input into a array so I can parse individually [0]1.5 [1]+ [2]4.2 [3]* [4]( [5]5 [6]+ [7]2 [8]) I have found out that the \b will work on 1+2+3 however if I were to have decimal points it would not split. I have tried splitting with \b(\.\d{1,2}) however it does not split on the decimal point
0
0
0
0
1
0
I have lists of articles made of: title, subtitle and body. Now I need to parse all these articles and group them up under different context categories or sub categories based on their possible keywords. e.g. if the article is likely to be related to sports cars then the article would be associated with the car or/and vehicle context Now I understand that this is a vast ocean, but this is also why I have put up this question. Because the ocean of solutions might be too big for me, and I would most likely get lost and adopt some bad thought solution. There are probably some popular and standardized ways of doing this that I do not know, and it would be very useful if someone pointed me in the right direction. Help would be great. =)
0
1
0
0
0
0
In the minmax algorithm,How to determine when your function reaches the end of the tree and break the recursive calls. I have made a max function in which I am calling the min function. In the min function , what shud I do?? For max function, I am just returning the bestscore. def maxAgent(gameState, depth): if (gameState.isWin()): return gameState.getScore() actions = gameState.getLegalActions(0); bestScore = -99999 bestAction = Directions.STOP for action in actions: if (action != Directions.STOP): score = minAgent(gameState.generateSuccessor(0, action), depth, 1) if (score > bestScore): bestScore = score bestAction = action return bestScore def minvalue(gameState,depth,agentIndex): if (gameState.isLose()): return gameState.getScore() else: finalstage = False number = gameState.getNumAgents() if (agentIndex == number-1): finalstage = True bestScore = 9999 for action in gameState.getLegalActions(agentIndex): if(action != Directions.STOP I could not understand how to proceed now?I not allowed to set the limit of depth of tree. it has to be arbitrary.
0
1
0
0
0
0
If I have 177 items, and each page has 10 items that means I'll have 18 pages. I'm new to python and having used any of the math related functions. How can I calculate 177/10 and then get round up so I get 18 and not 17.7
0
0
0
0
1
0
Vincent answered Fast Arc Cos algorithm by suggesting this function. float arccos(float x) { x = 1 - (x + 1); return pi * x / 2; } The question is, why x = 1 - (x + 1) and not x = -x?
0
0
0
0
1
0
Based on the documents http://www.gnu.org/software/gsl/manual/html_node/Householder-Transformations.html and http://en.wikipedia.org/wiki/Householder_transformation I figured the following code would successfully produce the matrix for reflection in the plane orthogonal to the unit vector normal_vector. gsl_matrix * reflection = gsl_matrix_alloc(3, 3); gsl_matrix_set_identity(reflection); gsl_linalg_householder_hm(2, normal_vector, reflection); However, the result is not a reflection matrix as far as I can tell. In particular in my case it has the real eigenvalue -(2 + 1/3), which is impossible for a reflection matrix. So my questions are: (1) What am I doing wrong? It seems like that should work to me. (2) If that approach doesn't work, does anyone know how to go about building such a matrix using gsl? [As a final note, I realize gsl provides functions for applying Householder transformations without actually finding the matrices. I actually need the matrices in my case for other work.]
0
0
0
0
1
0
I have the following date format: 2010-04-15 23:59:59 How would I go about converting this into: 15th Apr 2010 using javascript
0
1
0
0
0
0
Setup: I have a boolean matrix e.g. 1 0 1 1 0 1 where rows are named m1, m2, m3 (as methods) and columns t1 and t2 (as tests). Definition: An explanation is a set of rows (methods) which in union have at least one "1" in any column (every test hast to be matched by at least one method). in our example, the set of explanations would be: { {m2}, {m1,m2},{m1,m3},{m2,m3}, {m1,m2,m3} } Problem: I want now to calculate all explanations. Now, I already have two implementations which can solve the problem, one searching explanations top-down, the other bottom-up, but both suffer in exponential growth in computing time (doubles by increasing the number of rows by one). Is this a known (maybe solved efficiently) mathematical problem? What could make things easier is that at the end, I only need the number of occurrences in explanations for every method. In our example this would be for m1 three occurrences, for m2 four occurrences and for m3 three occurrences. My current algorithms work fine until let's say 26 rows. But further on, it is getting very slow. Thank you for your help!
0
0
0
0
1
0
Okay, I am looking for something akin to integral images (summed area tables) as used in the acceleration of integral calculations over a window. I have an image I and its gradient image G. I want to calculate the straight line integral from two arbitrary points a and b in the image of the absolute value of G. Obviously I can step over the line (1-t)a + t*b, t in [0, 1] and sum up given the right t step size. I want, however, to do this several million times so I would like some acceleration structure that preferably doesn't require me to run a loop for every pair (a, b). Does anyone know of an existing algorithm to accomplish this sort of thing?
0
0
0
0
1
0
I am looking to do some text analysis in a program I am writing. I am looking for alternate sources of text in its raw form similar to what is provided in the Wikipedia dumps (download.wikimedia.com). I'd rather not have to go through the trouble of crawling websites, trying to parse the html , extracting text etc..
0
1
0
0
0
0
Why is it that an arithmetic overflow cannot occur when adding an positive and a negative number using two's complement. If you could please provide an example with 8-bit signed integers (bytes).
0
0
0
0
1
0
I have an application which scrapes soccer results from different sources on the web. Team names are not consistent on different websites - eg Manchester United might be called 'Man Utd' on one site, 'Man United' on a second, 'Manchester United FC' on a third. I need to map all possible derivations back to a single name ('Manchester United'), and repeat the process for each of 20 teams in the league (Arsenal, Liverpool, Man City etc). Obviously I don't want any bad matches [eg 'Man City' being mapped to 'Manchester United']. Right now I specify regexes for all the possible combinations - eg 'Manchester United' would be 'man(chester)?(u|(utd)|(united))(fc)?'; this is fine for a couple of sites but is getting increasingly unwieldy. I'm looking for a solution which would avoid having to specify these regexes. Eg there must be a way to 'score' Man Utd so it gets a high score against 'Manchester United', but a low / zero score against 'Liverpool' [for example]; I'd test the sample text against all possible solutions and pick the one with the highest score. My sense is that the solution may be similar to the classic example of a neural net being trained to recognise handwriting [ie there is a fixed set of possible outcomes, and a degree of noise in the input samples] Anyone have any ideas ? Thanks.
0
1
0
1
0
0
What I mean by bandwagon effect describes itself like so: Already top-ranked items have a higher tendency to get voted on at all, possibly even to get upvoted. What I am hoping to get is some concrete recommendations, at best based on your practical experience with a mathematical formula and in which situation it helped. However, any useful pointers are more than welcome! My ranking system Please consider a ranking system at a website that has a reputation system and where users cast only upvotes on items and the ranking table is reset to start fresh every month. Every user has one upvote per item within each month, and there is a reward for users who, within a certain month, upvoted an item that made it into the top ranks at the end of that month. Users are told the following about what increases the weight of their upvote: 1)... the more reputation you have at the time of upvoting 2)... the fewer items you upvote within the current month (including the current upvote) 3)... the fewer upvotes that item already has within the current month before your own upvote The ranking table is recalculated once a day and is visible to all. Goal I'd like to implement part 3) in an effort to correct the ranks of items where one cannot tell if some users just upvoted it because of the bandwagon effect (those users might hope to gain a "tactical" advantage simply by voting what they perceive lots of other users already upvoted) Also, I hope to mitigate this way against the possible use of sock puppets that managed to attain some reputation, but upvote the same item or group of items. Question Is there a (maybe even tested?) mathematical formula that I could just apply on the time-ordered list of upvotes for each item to get a coffecient for each of those upvotes so that their weights will be corrected in a sensible fashion? I'm thinking it's got to be something of a lograthmic function but I can't quite get a grip on it... Thank you! Edit Zack says: "beyond a certain level of popularity, additional upvotes decrease the probability that something will be displayed" To further clarify: what I am after is which actual mathematical approaches are worth trying out that will, in the form of a mathematical function, translate this descrease in pop (i.e., apply coefficients to the weights, see above) in sensible, balanced manner. My hope is someone has practical experience with such approaches in a simmilar or general situation to the one above.
0
0
0
0
1
0
How can I implement the rightrotate (and leftrotate) operations on 32 bit integers without using any bitwise operations? I need this because High Level Shader Language (HLSL) does not allow bitwise oeprations upon numbers, and I need rightrotate for a specific shader I'm trying to implement.
0
0
0
0
1
0
I have following code: template<typename I,typename O> O convertRatio(I input, I inpMinLevel = std::numeric_limits<I>::min(), I inpMaxLevel = std::numeric_limits<I>::max(), O outMinLevel = std::numeric_limits<O>::min(), O outMaxLevel = std::numeric_limits<O>::max() ) { double inpRange = abs(double(inpMaxLevel - inpMinLevel)); double outRange = abs(double(outMaxLevel - outMinLevel)); double level = double(input)/inpRange; return O(outRange*level); } the usage is something like this: int value = convertRatio<float,int,-1.0f,1.0f>(0.5); //value is around 1073741823 ( a quarter range of signed int) the problem is for I=int and O=float with function default parameter: float value = convertRatio<int,float>(123456); the line double(inpMaxLevel - inpMinLevel) result is -1.0, and I expect it to be 4294967295 in float. do you have any idea to do it better? the base idea is just to convert a value from a range to another range with posibility of different data type.
0
0
0
0
1
0
$total = 30 - $nr1 / 13 - $nr2 - 6 * $nr3 - 3 I know we learned that in school but what is first (+ or - or * or /), where are the brackets or do I even need them ?
0
0
0
0
1
0
The general problem is projecting a polygon onto a plane is widely solved, but I was wondering if anybody could make some suggestions for my particular case. I have a planar polygon P in 3-space and I would like to project it onto the plane through the origin that is orthogonal to the unit vector u. The vertices of P and the coordinates of u are the only data I have (all w.r.t. the standard basis of R^3). However, I don't just want the projected coordinates. I actually would like to find an orthonormal basis of the plane orthogonal to u and to then find the coordinates of the projected vertices in this new basis. The basis itself doesn't matter so long as it is orthonormal. So really I need to do two things within the framework of the GNU Scientific Library: (1) Find two orthonormal basis vectors for the homogeneous plane orthogonal to the unit vector u. (2) Find the coordinates in this basis of the projection of P's vertices onto the plane. Any ideas on how to do this using gsl?
0
0
0
0
1
0
other than the standard arch options like left3words, left5words, bidirectional, bi5words, what do the rest of the options mean? And what arguments are needed for them? I can't seem to find the documentation anywhere!
0
1
0
0
0
0
is there common code available that produces square, triangle, sawtooth or any other custom waveforms using the math class? below is a basic function that handles a SampleDataEvent and plays a middle-c (440 Hz) sine wave. i'd like to change the tone by incorporating square, triangle and other waves. var position:int = 0; var sound:Sound = new Sound(); sound.addEventListener(SampleDataEvent.SAMPLE_DATA, sampleDataHandler); sound.play(); function sampleDataHandler(event:SampleDataEvent):void { for(var i:int = 0; i < 2048; i++) { var phase:Number = position / 44100 * Math.PI * 2; position ++; var sample:Number = Math.sin(phase * 440); event.data.writeFloat(sample); // left event.data.writeFloat(sample); // right } }
0
0
0
0
1
0
Say we have a list of rooms with their capacities and a list of meetings with the number of attendees. We want to match each meeting with one room in the following way: A meeting can only be scheduled in a room with capacity equal to or greater than its attendance. If surplus rooms are present, meetings should be scheduled so that the largest possible room is left unscheduled. A meeting with a larger attendance should not be scheduled in a smaller room than a meeting with a smaller attendance. Obviously we should find out if it is impossible to schedule the given meetings in the given rooms. Can we arrive at the schedule efficiently? A single pass would be nice, some backtracking is ok, but the only option I can get to work (a rough algorithm plus dynamically shaking out violations of rule 3) is slower than I would like. This question is not as easy as it looks! The naive linear approaches fail at least one criterion: We can sort each list from high-to-low and start pairing the largest room to the largest session, we will come up with a solution any time it is possible, but we will have the smallest possible rooms left over rather than the largest. (Consider the case of 10 and 15-person meetings scheduled in 200, 30, and 20-person capacity rooms.) We can sort the meeting list from high-to-low and then walk down it, trying to find the smallest room that is just large enough to contain this meeting. But sometimes this will result in a larger room being scheduled for a smaller meeting. (Consider scheduling 40 and 30-person meetings in 40 and 80-person rooms.) But surely there is a better way to solve this relatively simple problem.
0
0
0
0
1
0
Hey all, i am trying to figure out how to calculate the wage for an employee when they clock out. This is the code i am currently using: Dim theStartTime As Date Dim theEndTime As Date Dim totalTime As String theStartTime = "16:11:06" theEndTime = "18:22:01" totalTime = Format(CDbl((theEndTime - theStartTime) * 24), "#0.0") So workable hours would be: 2h 11m Right now, with my calculation code above, i get 2.2. What would i need to add in order to get it to calculate the correct time of 2:11 instead of 2:20? David
0
0
0
0
1
0
i have two spatial xyz file with different resolution how can i contour a composition of both files i like working with R or open source geographical systems like GMT if u know of a different way of solving this i would be glad to listen
0
0
0
0
1
0
I am using some code to subtract one date from another using XSLT 2.0: <xsl:template match="moveInDate"> <xsl:value-of select="current-date() - xs:date(.)"/> </xsl:template> This works, however it leaves me with an answer of P2243D, which I assume corresponds to a "Period of 2243 Days" (which is correct in terms of the math). Since I only need the number of days, not the P and the D, I know I could use substring or something similar, but as a newbie to XSLT, I'm curious if there is a better, more elegant way to do this than simple string manipulation.
0
0
0
0
1
0
I have to convert a floating point to 32-bit fixed point in Java . Not able to understand what is a 32-bit fixed point ? Can any body help with algorithm ?
0
0
0
0
1
0
I want to break a domain name into constituent words and numbers e.g. iamadomain11.com = ['i', 'am', 'a', 'domain', '11'] How do i do this? I am aware that there may be multiple sets possible, however, i am currently even ok, just getting 1 set of possibilities.
0
1
0
0
0
0
i have an object that is doing a circular motion in a 3d space, the center or the circle is at x:0,y:0,z:0 the radius is a variable. i know where the object is on the circle (by its angle [lets call that ar] or by the distance it has moved). the circle can be tilted in all 3 directions, so i got three variables for angles, lets call them ax,ay and az. now i need to calculate where exactly the object is in space. i need its x,y and z coordinates. float radius = someValue; float ax = someValue; float ay = someValue; float az = someValue; float ar = someValue; //this is representing the angle of the object on circle //what i need to know object.x = ?; object.y = ?; object.z = ?;
0
0
0
0
1
0
Tommy, jill and travelor belong to the Sc club.Every member of sc club is either a surfer or a bike rider or both.No bike rider likes a rainy day and all the surfers like a sunny day.Jill like whatever Tommy likes and likes whatever tommy dislikes.Tommy likes a rainy day and a sunny day. I want to represent the above information in first order predicate logic in such a way that I can represent the question " who is a member of SC club who is a bike rider but not a surfer?" as a predicate logic expression. What first order inference rule I should pick- forward chaining, backward chaining, or resolution refutation.??
0
1
0
0
0
0
I do not know a whole lot about math, so I don't know how to begin to google what I am looking for, so I rely on the intelligence of experts to help me understand what I am after... I am trying to find the smallest string of equations for a particular large number. For example given the number "39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806627990306816" The smallest equation is 64^64 (that I know of) . It contains only 5 bytes. Basically the program would reverse the math, instead of taking an expression and finding an answer, it takes an answer and finds the most simplistic expression. Simplistic is this case means smallest string, not really simple math. Has this already been created? If so where can I find it? I am looking to take extremely HUGE numbers (10^10000000) and break them down to hopefully expressions that will be like 100 characters in length. Is this even possible? are modern CPUs/GPUs not capable of doing such big calculations? Edit: Ok. So finding the smallest equation takes WAY too much time, judging on answers. Is there anyway to bruteforce this and get the smallest found thus far? For example given a number super super large. Sometimes taking the sqaureroot of number will result in an expression smaller than the number itself. As far as what expressions it would start off it, well it would naturally try expressions that would the expression the smallest. I am sure there is tons of math things I dont know, but one of the ways to make a number a lot smaller is powers.
0
0
0
0
1
0
How to draw the spring like shape using c# drawing class alt text http://img812.imageshack.us/img812/373/spring.jpg
0
0
0
0
1
0
I'm trying to figure out an algorithm for finding a random point a set distance away from a base point. So for example: This could just be basic maths and my brain not working yet (forgive me, haven't had my coffee yet :) ), but I've been trying to work this out on paper and I'm not getting anywhere.
0
0
0
0
1
0
I have an algorithm that generates strings based on a list of input words. How do I separate only the strings that sounds like English words? ie. discard RDLO while keeping LORD. EDIT: To clarify, they do not need to be actual words in the dictionary. They just need to sound like English. For example KEAL would be accepted.
0
1
0
0
0
0