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
Multiplication of two n-bit numbers A and B can be understood as a sum of shifts: (A << i1) + (A << i2) + ... where i1, i2, ... are numbers of bits that are set to 1 in B. Now lets replace PLUS with OR to get new operation I actually need: (A << i1) | (A << i2) | ... This operation is quite similar to regular multiplication for which there exists many faster algorithms (Schönhage-Strassen for example). Is a similar algorithm for operation I presented here? The size of the numbers is 6000 bits. edit: For some reason I have no link/button to post comments (any idea why?) so I will edit my question insead. I indeed search for faster than O(n^2) algorithm for the operation defined above. And yes, I am aware that it is not ordinary multiplication.
0
0
0
0
1
0
I know: The control points a and d (start and end point of a 2D cubic bezier curve) The slopes a->b, c->d, and b->c (b,c the other control points) Where the halfway point of the Bézier curve is. Now, given this information, what is the formula for the positions of control points b and c ?
0
0
0
0
1
0
I know this is not a straight up question, so if you need me to provide more information about the scope of it, let me know. There are a bunch of questions that address almost the same issue (they are linked here), but never the exact same one with the same kind of scope and objective - at least as far as I know. Context: I have a MP3 file with ID3 tags for artist name and song title. I have two tables Artists and Songs The ID3 tags might be slightly off (e.g. Mikaell Jacksonne) I'm using ASP.NET + C# and a MSSQL database I need to synchronize the MP3s with the database. Meaning: The user launches a script The script browses through all the MP3s The script says "Is 'Mikaell Jacksonne' 'Michael Jackson' YES/NO" The user pick and we start over Examples of what the system could find: In the database... SONGS = {"This is a great song title", "This is a song title"} ARTISTS = {"Michael Jackson"} Outputs... "This is a grt song title" did you mean "This is a great song title" ? "This is song title" did you mean "This is a song title" ? "This si a song title" did you mean "This is a song title" ? "This si song a title" did you mean "This is a song title" ? "Jackson, Michael" did you mean "Michael Jackson" ? "JacksonMichael" did you mean "Michael Jackson" ? "Michael Jacksno" did you mean "Michael Jackson" ? etc. I read some documentation from this /how-do-you-implement-a-did-you-mean and this is not exactly what I need since I don't want to check an entire dictionary. I also can't really use a web service since it's depending a lot on what I already have in my database. If possible I'd also like to avoid dealing with distances and other complicated things. I could use the google api (or something similar) to do this, meaning that the script will try spell checking and test it with the database, but I feel there could be a better solution since my database might end up being really specific with weird songs and artists, making spell checking useless. I could also try something like what has been explained on this post, using Soundex for c#. Using a regular spell checker won't work because I won't be using words but names and 'titles'. So my question is: is there a relatively simple way of doing this, and if so, what is it? Any kind of help would be appreciated. Thanks!
0
1
0
0
0
0
History: I read from one of Knuth's algorithm book that first computers used the base of 10. Then, it switched to two's complement here. Question: Why does the base could not be -2 in at least a monoid? Examples: (-2)^1 = -2 (-2)^3 = -8
0
0
0
0
1
0
An object is positioned at A and wants to move to B. I want to calculate a movement vector there that doesn't move within the distance D of the to-be-avoided points in array C. So if the move vector (B-A) normalized and multiplied with the objects speed would bring it within D of any point in C the vector is rotated so that it doesn't. This is in two dimensions. Also, if this operation has a name, please make a comment or edit this question yourself as I had no idea of what to call it. Also, my first instinct was to divide the active area into nodes and run a A* but I want to try the mathematical approach on this one, a few experiments with flocking gives me the impression that it can be done. Update (from comments): This image is very close to the solution I want: Assuming we start at the point to the left, we start turning right towards the goal (the other point), we detect a wall on the right so we stop turning and move forward. The wall is gone so we are allowed to start turning towards the goal again, and so on. I know this may cause the object to not get there at all, but I want to define a behavior, not necessarily a solution, if you know what I mean. Update2: Translating the active area into a set of nodes might prove inefficient. A* and other heuristic graph traversal algorithms are great for low dimensional problems. But the area I want to move across is infinite in size and only has a handful of obstacles scattered across it. The nodes themselves, or rather the potential positions, are infinitely small. This could of course be optimized with a quad tree of some sort but I have a feeling simple movement vectors that are in some way rotated and interpolated can solve this as well.
0
0
0
0
1
0
i need to implement a genetic algorithm customized for my problem (college project), and the first version had it coded as an matrix of short ( bits per chromosome x size of population). That was a bad design, since i am declaring a short but only using the "0" and "1" values... but it was just a prototype and it worked as intended, and now it is time for me to develop a new, improved version. Performance is important here, but simplicity is also appreciated. I researched around and came up with: for the chromosome : - String class (like "0100100010") - Array of bool - Vector (vectors appears to be optimized for bool) - Bitset (sounds the most natural one) and for the population: - C Array[] - Vector - Queue I am inclined to pick vector for chromossome and array for pop, but i would like the opinion of anyone with experience on the subject. Thanks in advance!
0
1
0
0
0
0
I'm building, for example, an application that monitors your health. Each day, you're jogging and doing push-ups and you enter the information on a web site. What I would like to do is building a chart combining the hours you jogged and the number of push-ups/sit-ups you did. Let's say on the first day, you jogged 1 hour and did 10 push-ups and on the second day, you jogged 50 minutes and did 20 push-ups, you would see a progression in your training. I know it may sound strange but I want to have an overall-view of your health, not different views for jogging and push-ups. I don't want a double y-axis chart because if I have, as example, 6 runners, I will end up with 12 lines on the chart.
0
0
0
0
1
0
I'd like to know if there are any libraries (preferably DateTime-esque) that can take a normal date time and create an appropriate relative human readable date. Essentially the exact opposite of the more common question: How can I parse relative dates with Perl?. Obviously, the exact wording/interpretation is up to the actual implementation, but I'm looking to provide a consistent way to specify dates in the future. Knowing an apporximation like "due in 2 weeks" is (to me) more helpful in getting a grasp of how much time I have remaining than something "due on 2009-07-30". Examples: 2009-07-06 => "in 1 year" 2009-07-30 => "in 2 weeks" 2009-07-09 => "tomorrow" 2009-07-09 12:32 => "tomorrow at 12:32" 2009-07-12 05:43 => "monday morning" 2009-07-03 05:74 => "6 days ago"
0
1
0
0
0
0
I want to find a Calculate Library not a Drawing Library to help me do some graphics calulation like Bezier's length, point on Beziers or other metadata. Is there any library like this?
0
0
0
0
1
0
What should 'foo' be called, given the following? x.items is a set, y.values is a set. function a(key) returns an ordered list of x.items function b(x.item) returns a single y.value Define foo(a, b), which returns a function, d, such that d(key) returns a list of y.values defined by: map(b, a(key)). This feels like a fairly common and generic function composition but I don't know what to call it.
0
0
0
0
1
0
The image below was scanned (poorly) from Computer Systems: A Programmer's Perspective. (I apologize to the publisher). This appears on page 489. Figure 6.26: Summary of cache parameters http://theopensourceu.com/wp-content/uploads/2009/07/Figure-6.26.jpg I'm having a terribly difficult time understanding some of these calculations. At the current moment, what is troubling me is the calculation for M, which is supposed to be the number of unique addresses. "Maximum number of unique memory addresses." What does 2m suppose to mean? I think m is calculated as log2(M). This seems circular.... For the sake of this post, assume the following in the event you want to draw up an example: 512 sets, 8 blocks per set, 32 words per block, 8 bits per word Update: All of the answers posted thus far have been helpful but I still think I'm missing something. cwrea's answer provides the biggest bridge for my understand. I feel like the answer is on the tip of my mental tongue. I know it is there but I can't identify it. Why does M = 2m but then m = log2(M)? Perhaps the detail I'm missing is that for a 32-bit machine, we'd assume M = 232. Does this single fact allow me to solve for m? m = log2(232)? But then this gets me back to 32... I have to be missing something...
0
0
0
0
1
0
I have the following radial gradient: <radialGradient inkscape:collect="always" xlink:href="#linearGradient2454" id="radialGradient2460" cx="4022.8572" cy="5451.2656" fx="4022.8572" fy="5451.2656" r="3559.865" gradientTransform="matrix(-0.1071067,-0.1166362,0.1377765,-7.0459663e-2,276.61943,1452.439)" gradientUnits="userSpaceOnUse" /> I'd like to reduce this gradient in size by 90% and translate it appropriately based upon this new scale (x position becomes 402.2, y position becomes 545.1, etc). Obviously, multiplying cx, cy, fx, fy, and r by .1 will get me part of the way there. However, how do I programatically rework the gradientTransform to get the rest of the way?
0
0
0
0
1
0
In the picture below you can see a learning algorithm trying to learn to produce a desired output (the red line). The learning algorithm is similar to a backward error propagation neural network. The "learning rate" is a value that controls the size of the adjustments made during the training process. If the learning rate is too high, then the algorithm learns quickly but its predictions jump around a lot during the training process (green line - learning rate of 0.001), if it is lower then the predictions jump around less, but the algorithm takes a lot longer to learn (blue line - learning rate of 0.0001). The black lines are moving averages. How can I adapt the learning rate so that it converges to close to the desired output initially, but then slows down so that it can hone in on the correct value? learning rate graph http://img.skitch.com/20090605-pqpkse1yr1e5r869y6eehmpsym.png
0
0
0
1
0
0
I'm wondering if this is a sufficient algorithm for finding the best value with a weighted system. Is there anything I could add to make it better? in this example I would like the probability of $object->get() returning test4 to be 4 times greater than the probability of it returning test1. class weightCalculator { var $data = array(); var $universe = 0; function add( $data, $probability ){ $this->data[ $x = sizeof( $this->data ) ] = new stdClass; $this->data[ $x ]->value = $data; $this->universe += $this->data[ $x ]->probability = abs( $probability ); } function get(){ if( !$this->universe ){ return null; } $x = round( mt_rand( 0, $this->universe ) ); $max = 0; $i = 0; while( $x > $max ){ $max += $this->data[ $i++ ]->probability; } $val=-1; if($this->universe==1){ $val = $this->data[$i]->value; } else { $val = $this->data[$i-1]->value; } return $val; } } $object = new weightCalculator; $object->add( 'test1', 10 ); $object->add( 'test2', 20 ); $object->add( 'test3', 30 ); $object->add( 'test4', 40 );
0
0
0
0
1
0
Trying to find a good name for a method swapping each coordinate X and Y values. Is there a name for this operation? Essentially, here's what is done (1, 2) -> (2, 1) On a polygon, this is the same as having a rotation of -90 degrees and doing a horizontal flip or mirror.
0
0
0
0
1
0
I try to store the PHP floating point value 63.59072952118762 into a double precision column in postgres. Postgres stores the value as 63.59073. Does anyone know why? 8 byte should be more than enough for that value. I've tried with the data type numeric, which works when specifying the precision, but that shouldn't really be necessary. Update: The same problem is present when trying to store 63.5907295, so the suggestion that something happens with the double before it's getting stored seems realistic. Update II (partly solved): The line where I assign the double parameter looks like this: $stmt->bindParam(4, $this->latitude); The thing I didn't know is that PDO defaults its param type to string. I changed it to PDO::PARAM INT in lack of a better alternative (PARAM DOUBLE was not an option), and got 10 digits precision in the double stored in postgres (some progress, at least). I've checked that the numeric type works well, so it seems that numeric is the way to go when using PDO and doubles that has to have a precision of more than 10 decimals. Anyways, as someone has mentioned, I don't know if it's a must for me to have this kind of precision, but I think the problem in itself deserved to be investigated.
0
0
0
0
1
0
Is there a filtering algorithm that converges at some shape? My problem is that I am filtering a two dimensional graph, and applying filtering repeatedly. I'm down-sampling data and re-sampling it using gaussian filters (footprints), but the graph changes its shape with every subsequent filtering. What I need is to achieve some final shape, so that after enough filtering, the graph will no longer change shape. EDIT: by filtering I mean smoothing out, not dropping some information.
0
0
0
0
1
0
I need your help, and thank you for reading my question! I am currently writing a java Programm that will use an Direket Form 2 Transposed Filter. I know that the function filter in Matlab will do that just fine, but i have to use Java. So does anyone know you to implement this Direkt Form 2 Transposed , this Math Function: y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) - a(2)*y(n-1) - ... - a(na+1)*y(n-na) in any Programmm Language? All it takes is hopefully a point to the wrigth direction so i can figure it out! Maybe there is an C Lib that implements some of the matlab functions, just anything. So thank you for your time yours Elektro Follow up: I tried for a couple of days to understand your function but i couldn't. This is the function from Matlab: filter http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/filter.html&http://www.google.de/search?hl=de&q=filter+matlab&btnG=Google-Suche&meta=&aq=f&oq= All i know is that i use in matlab the function like this: newArray = filter(1,LPC_Faktor,OldArray) All I have to do is to implement the filter function. So could you help again? Thanks Elektro
0
0
0
0
1
0
I work for a market research company in the online space. We have been spending all of our cycles for over a year and a half building the next big thing in this space with regards to profiling our respondents (over time) to better place them in available surveys . Something that one of our researcher's has asked us for many times (rightly so) is a tool that will prove the worth of this new profiling system and predict the outcome of tweaks to it's many algorithms and rules to show which version of a rule set has a better outcome. The goal is to be able to take a sliver of our profiling system (a static slice of Q&A data for a given time - sex:male/female, drinks:coke/pepsi/mt.dew, income:etc.) and run user agents (artificially developed software robots or agents) through our profiling system to see what the interactive results would be. As the Q&A data would be the same, the user agents abilities to choose answers would be the same, and only the algorithms and rules behind how the profiler works would change - this theoretically would allow us to pre-determine the outcome of any changes to our system. This result would then allow us to proof changes before pushing the changes to our production system. The hope would be that we could more easily catch any errors before releasing to the wild. But this would also allow us to test changes to the logic to hunt for optimizations in the profiler. My question: For someone like me (C#/.NET mostly) who has really only worked in the web application space, where do I look to get started in building user agents that are able to interact with an outside system such as my profiling system? I specifically need to know how to spin up 1000 (one thousand) agents and have them interact with my profiling system (over a given amount of time) by being able to answer the questions that are presented to them by the profiling system based on characteristics that are dynamically defined on the user agent at the time of initialization. An example of this is that I need some black agents, some chinese agents, some male agents, some female agents, some old agents, some new agents, some religious agents, some that drink coke, etc. and all of them mixed together to most appropriately resemble the world. We already have the demographic break down of our population so we can easily spin up 10% black males, 60% white female stay at home mothers, and all the other representations of our population. My first thoughts for creating a system like this was to use the power of my XBOX 360, and some well thought out agents that resemble a person from an object oriented world with some added characteristics to be able to intelligently answer some questions...and guess at others. In speaking with my colleague, it was suggested that I use some of the artificial intelligence frameworks out there and a 1000 cpu graphics card (we have one already) to get some super wicked fast performance out of loads of user agents. Where each CPU is an agent...(something like this). Is there anyone out there with experience in this sort of thing? Proofing problems with a fictitious model of the world?
0
1
0
0
0
0
Hi i am trying to create the affine transform that will allow me to transform a triangle into another one. What i have are the coordinates for the 2 triangles. Can you help me? Following the answer by Adam Rosenfield i came up with this code in case anyone is bored to solve the equation himself : public static AffineTransform createTransform(ThreePointSystem source, ThreePointSystem dest) { double x11 = source.point1.getX(); double x12 = source.point1.getY(); double x21 = source.point2.getX(); double x22 = source.point2.getY(); double x31 = source.point3.getX(); double x32 = source.point3.getY(); double y11 = dest.point1.getX(); double y12 = dest.point1.getY(); double y21 = dest.point2.getX(); double y22 = dest.point2.getY(); double y31 = dest.point3.getX(); double y32 = dest.point3.getY(); double a1 = ((y11-y21)*(x12-x32)-(y11-y31)*(x12-x22))/ ((x11-x21)*(x12-x32)-(x11-x31)*(x12-x22)); double a2 = ((y11-y21)*(x11-x31)-(y11-y31)*(x11-x21))/ ((x12-x22)*(x11-x31)-(x12-x32)*(x11-x21)); double a3 = y11-a1*x11-a2*x12; double a4 = ((y12-y22)*(x12-x32)-(y12-y32)*(x12-x22))/ ((x11-x21)*(x12-x32)-(x11-x31)*(x12-x22)); double a5 = ((y12-y22)*(x11-x31)-(y12-y32)*(x11-x21))/ ((x12-x22)*(x11-x31)-(x12-x32)*(x11-x21)); double a6 = y12-a4*x11-a5*x12; return new AffineTransform(a1, a4, a2, a5, a3, a6); }
0
0
0
0
1
0
I taken math in college (trigonometry, calculus II...) but I don't know why you use tan, arctan, etc., in game physics. I know I can find working code and understand everything except why I am using a particular trig function, but I don't want that. I want to know why I am using arctan or sin. Where can I learn about why I am using that particular math function to make a ball bounce realistically? Thanks for any help. EDIT: Do I need to have taken an entry level physics class to understand game physics?
0
0
0
0
1
0
Related to my question here but not enough to open a new question. I wanted to make a good tower defense game and found this site. I saw math in it and made the mental leap that it was "game physics." Maybe it's not. I don't know. I was hoping someone could tell me. If it is not what kind of game programming is it? Just math you have to know for angles and what not (they have a tutorial here.) Is this 2d game mechanics/physics? I know nothing about the site. Just one that game up in google. Thank you again.
0
0
0
0
1
0
I'm not sure if this is for SO or not. I am reading some of my old math textbooks and trying to understand math in general. Not how to figure something. I can do that but rather what is it that math is doing. I'm sure this is painfully obvious but I never thought about it until I thought more about game programming. Is it right to think about math as the "language" that is used to explain, precisely explain, why things work? I'm having a hard time asking it and again, I'm sure it's obvious to most, but after years of math I'm finally thinking when someone asks to "find the equation of a line" that people recognized certain characteristics of a line (y=mx+b) in space and found relationship. They needed something beside a huge paragraph (like this one) and something very precise. We call this math and at its base it's nothing more than a symbolic way to represent things. Really, I was thinking, "I know why they said 'find the equation of a line'." So now I am thinking, not just googling for a formula that tells me how to turn a curve with a walking man or follow a path, but why and how do I represent this mathematically and then programatically. Just hoping for comments on math in programming.
0
0
0
0
1
0
I'm trying to build a rectangular grid that can wrap around at the edges. Anyone who plays video games will probably be familiar with the concept: go far enough in one direction on the world map and you'll end up back where you started. This causes some difficulty in setting up the viewport, though, since the edges can scroll into negative coordinate territory. It's easy enough to take a negative coordinate and determine its real value: function GetRealCoords(value: TPoint): TPoint; begin result := ModPoints(AddPoints(value, MAP_SIZE), MAP_SIZE); end; where AddPoints and ModPoints simply apply the + and mod operators, respectively, to each coordinate of the two inputs to produce an output value. The trouble is reversing this operation. Given a point in which both coordinates are positive and a TRect in which the Top and Left values could be positive or negative, (and the Bottom or Right could be beyond the edges of the map,) and with MAP_SIZE declared at global scope, is there any way to determine whether the point falls within the territory covered by the viewing rectangle without having to run the same calculation up to four different times?
0
0
0
0
1
0
I would like to use Python to generate my own algebra to pre-calculus worksheets to print and use. The purpose is to teach kids how to practice algebra. What is the best way generate the expressions? Update: I am planning to use Latex to generate nicely formatted equations. The question I have is how to come up with a large number of the equations. One way of doing this is to define the list for each topics but this is tedious. I want to automate using some kind generator (e.g. Context Free Grammar)
0
0
0
0
1
0
I was working on some grouping problems at my work. There are quite a few questions, please bear with me. I find them quite interesting. If anyone here is also interested in combinatorics, please help me out. Ok so we have a bunch of characters , here i have taken a i d s. What are the ways we can group the elements ? Let us say we have 4 characters a i d s. Valid groups(preserving the order) would be: a i d s a i ds a id s ai d s ai ds a ids aid s aids How do you enumerate all the groups? Could you tell me how many combinations are there for any n letters? 2 . Special Cases What if the case made a difference like Ai sd and ai sd are two groups? How much time would it take you to enumerate all the cases? What would be the time difference between finding the 4 letters and 5 letters case? If you take the "blank space" as a character. After all the enumeration, how many characters would you have written? If you define a transformation from a word to another word in terms of distance. Say "ai ds" and "a i ds" has 1 distance because you should moved the letter "i" one step. Could you find the words at n distance in either side of any word? Edit: "aids" is a single word. "a ids" "aid s" are two words which are at 1 distance from the original word "aids". "a id s" is a word which is two distance from the original word "aids". "a i d s" is a word which is three distance from the word. This problem seems to be gold mine. Bonus:What is the smallest distance between two words. Like "aids" is one distance from "a ids" and also two distance. Is there a "midpoint" word from where you can reach any other word in the enumeration with least distance? How many paths are there from a word to another?
0
0
0
0
1
0
I'm wondering if in MySQL you are able to find a range within values along with the average in a query. Assume the table below please: ----------------------------------------- | ID | VALUE | ----------------------------------------- | 1 | 30 | ----------------------------------------- | 2 | 50 | ----------------------------------------- | 3 | 10 | ----------------------------------------- Range Low would be 10, range High would be 50, average would be 30. Is there query that would allow me to grab these values without pulling them down into php and then sorting the array, and finding the average that way? Cheers
0
0
0
0
1
0
I'm looking to write a quick benchmark program that can be compiled and run on various machines. Rather than using commercially/open-sourceally available options, I'd rather have my own to play around with threading and algorithm optimization techniques. I have a couple that I use already, which include recursively calculating the nth number of the Fibonacci sequence, and of seeding/rand()ing a few thousand times. Are there any other algorithms that are relatively simple, but at the same time computationally-intensive (and possibly math-related)? (Note that these operations will be implemented in the C language.)
0
0
0
0
1
0
I have an array which tells whether a card is in use: int used[52]; This is a terrible way to pick a random card if I have many used cards: do { card = rand() % 52; } while (used[card]); since if I have only 3-4 unused cards, it'll take forever to find them. I came up with this: int card; int k = 0; int numUsed = 0; for (k=0; k < 52; ++k) { if (used[k]) numUsed += 1; } if (numUsed == 52) return -1; card = rand() % (52 - numUsed); for (k=0; k < 52; ++k) { if (used[k]) continue; if (card == 0) return k; card -= 1; } which I guess works better if the deck is full, but works worse when the deck is empty since I have to go through two for loops. What's the most efficient way to do this?
0
0
0
0
1
0
I am having some weird issue here. I have a database table which has huge value stored on a column. My application (C#) is reading this value and keeping in a double type. This application will insert the same value to another table. Note : I am not doing any calculations/processing on the value read from the first table. It is just kept for updating the second table. Issue here is, the second table is getting slightly different value than in the first table. Looks like the number is rounding off when I keep in the double type. Here is an example of values. Original Value : 18014398509481984 Value copied to new table : 18014398509482000 The values looks different, but both are same in reality. I did a google search with 18014398509481984 - 18014398509482000 as a search term and it returned result 0, which means both are same. Questions: 1 - If both are same, why the second value looks different? I can see 1984 turned into 2000. 2 - Why the conversion happens? 3 - How can I avoid this type of conversions? Any help would be great!
0
0
0
0
1
0
I'm writing a computer graphics application that makes use of several different libraries that provide many of the required features. For example, in college I wrote quaternion, optimized 3 vector, and optimized 4x4 matrix classes that I like to use since they are efficient and I'm very familiar with them. I also wrote a K-D Tree implementation that only depends on the STL. Finally, I'm using ITK to compute the minimum eigenvalue (and associated eigenvector) of a given symmetric real matrix, among other things. With all of these libraries containing their own matrix and vector implementations, I find myself doing a lot of this sort of thing: FixedPointType closestPointCoords; KdTree::HyperPoint target(3); target[0] = transformedPoint[0]; target[1] = transformedPoint[1]; target[2] = transformedPoint[2]; KdTree::Neighbor result = FixedPointTree.FindNearestNeighbor(target); minimumDistance = result.GetDistance(); closestPointCoords[0] = result.GetPoint().Get(0); closestPointCoords[1] = result.GetPoint().Get(1); closestPointCoords[2] = result.GetPoint().Get(2); Obviously I could write a function that looks something like: FixedPointType ConvertHyperPointToFixedPointType(const KdTree::HyperPoint &p) { FixedPointType fixedPoint; fixedPoint[0] = p[0]; fixedPoint[1] = p[1]; fixedPoint[2] = p[2]; return fixedPoint; } I'd like to avoid adding inter-library dependancy by doing something like this: class HyperPoint { ... operator FixedPointType() { // Same content as ConvertHyperPointToFixedPointType above } ... }; But I'm wondering if anyone has come up with a more elegant solution to this problem. Perhaps I should take a page out of the .NET book and create a static Convert class? How have you handled type redundancy across libraries and the need to frequently convert between the various types? Is the Adapter pattern appropriate here? UPDATE After some more exploring I came across TypeConverter. So this problem looks like it's been addressed in C#. I'm still looking for a clean, efficient and simple way to do it in C++. So far I'm thinking the canonical types, or maybe just the bare ConvertHyperPointToFixedPointType kind of functions. UPDATE 2 After even more reading it sounds like the canonical type will actually act as the shim. See this paper for more info. Here's some sample code to illustrate my current inclination: class VectorConverter { public: VectorConverter(const VectorImp1 &v1) { _data[0] = v1[0]; _data[1] = v1[1]; _data[2] = v1[2]; } VectorConverter(const VectorImp2 &v2) { _data[0] = v2.Get(0); _data[1] = v2.Get(1); _data[2] = v2.Get(2); } operator VectorImp1() { return VectorImp1(_data[0], _data[1], _data[2]); } operator VectorImp2() { VectorImp2 v2; v2.Set(0, _data[0]); v2.Set(1, _data[1]); v2.Set(2, _data[2]); return v2; } // actual vector implementation goes here or a wrapper around an existing one }; // example usage VectorImp1 closestPointCoords, target; // for the sake of illustration I included the cast, but you could implicitly cast KdTree::Neighbor result = FixedPointTree.FindNearestNeighbor((VectorImp2)VectorConverter(target)); minimumDistance = result.GetDistance(); closestPointCoords = (VectorImp1)VectorConverter(result.GetPoint()); Thanks for all your help. Feel free to update this post if someone comes across something better.
0
0
0
0
1
0
I would like to know 2 things about the struct Vector2 in XNA: Why does this struct only have X and Y instead of X,Y (origin) and X',Y' (destination)? How can I calculate the direction of a vector with only the X,Y? Thanks a lot in advance. Kind Regards. Josema.
0
0
0
0
1
0
I need to sort some products base on user ratings. Suppose we have 3 products {a,b,c} and we have user's feed backs about this products. It's not important which user give us feed back (this question is not about correlative filtering if you are familiar with it - user interests is not the case here) Each of these below lines are feed backs from users when they tried to compare the 3 products: a 150 points - b 0 points (this user just told us what he thinks of 2 products a and b and in comparison of a and b he though that if he gives a 150 point then b worth 0 point) a 150 points - c 20 points c 200 points - a 10 points (despite the previous one this user thinks that c is better that a) a 200 points - b 40 points - c 100 points a 150 points - b 50 points a 150 points - b 20 points (These ratings are just a sample and in the real world number of products and ratings are much bigger than this) Now I need an algorithm to find product's rankings based on user votes. In my point of view the best way is to describe this problem with a correlation graph and connect all products to each other. Any kind of help or tips is appreciated. /******************************************************************************/** you cannot just add the points and calculate the mean of product's points Cause it's important how it got his points suppose a has got 800 points against b - then c get 10 points against a like this: a 200 - b 0 a 200 - b 0 a 200 - b 0 a 200 - b 0 c 10 - a 0 (this means that c is better than a) so definitely a is better than b but with a small 10 points c got a better rank from a /****************************************************************************/
0
0
0
0
1
0
I need to sort some products base on user ratings. Suppose we have 3 products {a,b,c} and we have user's feedbacks about this products. It's not important which user give us feedback (this question is not about correlative filtering if you are familiar with it - user interests is not the case here) Each of these below lines is feedback from users when they tried to compare the 3 products: a 150 points - b 0 points (this user just told us what he thinks of 2 products a and b and in comparison of a and b he thought that if he gives a 150 point then b worth 0 points) a 150 points - c 20 points c 200 points - a 10 points (despite the previous one this user thinks that c is better that a) a 200 points - b 40 points - c 100 points a 150 points - b 50 points a 150 points - b 20 points (These ratings are just a sample and in the real world number of products and ratings are much bigger than this) Now I need an algorithm to find product's rankings based on user votes. In my point of view, the best way is to describe this problem with a correlation graph and connect all the products to each other. Any kind of help or tips is appreciated. /********************************************************************************/ You cannot just add the points and calculate the mean of product's points because it's important how it got his points. Suppose a has got 800 points against b - then c get 10 points against a like this: a 200 - b 0 a 200 - b 0 a 200 - b 0 a 200 - b 0 c 10 - a 0 (this means that c is better than a) so definitely a is better than b but with a small 10 points c got a better rank from a /********************************************************************************/
0
0
0
0
1
0
I was asked by my boss to create a module for calculating reverse compound. The question is: if I want to achieve $1.000.000,00 in 24 months with interest rate 18%/year (or 1.5%/month). how much money do I have to save every month? I searched on the internet, but found nothing except people referring to the Excel formula. Do you know what the mathematical formula is for this case? I am using Java for this module. Is there any Java library or API?
0
0
0
0
1
0
This is the problem: I have n points (p1, p2, p3, .. pn), each of them can connect to any other with a determined cost x. Each point belongs to one of a set of point-types (for example "A" "B" "C" "D"...). The input of the method is the path I want to follow, for example "A-B-C-A-D-B". The output is the shortest path connecting the points of the type I give in input so for example "p1-p4-p32-p83-p43-p12" where p1 is an A-type, p4 a B-type, p32 a C-type, p83 an A-type, p43 a D-type and p12 a B-type. The "easy" solution consists of calculating ALL the possible paths but the computational cost is very high! Can someone find a better algorithm? As I said in title, I don't know if it exists! Update: The key point that prevents me from using Dijkstra and the other similar algorithms is that I have to link the points according to type. As input I have an array of types and I have to link in that order. This is an image of Kent Fredric (thanks a lot) which describes the initial situation (in red allowed links)! A real life example: A man wants to visit a church in the morning, go to restaurant and finally visit a museum in the afternoon. In the map there are 6 churchs, 30 restaurants and 4 museums. He wants that the distance church-rest-museum is the minimum possible.
0
0
0
0
1
0
I am building a project involving natural language processing, since the nlp module currently only deal with english text, so I have to make sure the user submitted content (not long, only several words) is in english. Are there established ways to achieve this? Python or Javascript way preferred.
0
1
0
0
0
0
I'm building a binary classification tree using mutual information gain as the splitting function. But since the training data is skewed toward a few classes, it is advisable to weight each training example by the inverse class frequency. How do I weight the training data? When calculating the probabilities to estimate the entropy, do I take weighted averages? EDIT: I'd like an expression for entropy with the weights.
0
0
0
1
0
0
In Python, there are examples of built-in classes with highly constrained instances. For example, "None" is the only instance of its class, and in the bool class there are only two objects, "True" and "False" (I hope I am more-or-less correct so far). Another good example are integers: if a and b are instances of the int type then a == b implies that a is b. Two questions: How does one create a class with similarly constrained instances? For example we could ask for a class with exactly 5 instances. Or there could be infinitely many instances, like type int, but these are not arbitrary. if integers form a class, why does int() give the 0 instance? compare this to a user-defined class Cl, where Cl() would give an instance of the class, not a specific unique instance, like 0. Shouldn't int() return an unspecified integer object, i.e. an integer without a specified value?
0
0
0
0
1
0
I am currently using scipy's linregress function for single regression. I am unable to find if the same library, or another, is able to do multiple regression, that is, one dependent variable and more than one independent variable. I'd like to avoid R if possible. If you're wondering, I am doing FX market analysis with the goal of replicating one currency pair with multiple other currency pairs. Anyone help? Thanks, Thomas
0
0
0
0
1
0
We've developed a WinForms application (targeting .NET 2.0 with VS2008), we've just found out that we need to localize it for use in another language (other than english) :( What are the guidelines for developing multi-lingual languages in .NET? Another application borrows Paint.NET's idea of globalization (using resources) but I was wondering if there are tools out there than can automate this for us - free would be nice but commercial is OK too. Any ideas? How do people normally work on projects that require multi-lingual interfaces? We're talking WiNForms apps. Do you just use IsLocalized = true and let .NET handle it?
0
1
0
0
0
0
I am using UIAcceleration for rotation. I have opposite side, adjacent side, but I want to calculate tan-1(y/x) inverse tan.
0
0
0
0
1
0
I'm currently reading from a depth texture in a postprocess depth of field shader using the following GLSL code: vec4 depthSample = texture2D(sDepthTexture, tcScreen); float depth = depthSample.x * 255.0 / 256.0 + depthSample.y * 255.0 / 65536.0 + depthSample.z * 255.0 / 16777216.0; And then converting the depth value to a view space distance based on the near and far plane distances: float zDistance = (zNear * zFar) / (zFar - depth * (zFar - zNear)); This all seems to work fairly well, however I am interested to know how to do the above calculation based only on the current projection matrix without needing separate zNear and zFar values. My initial attempt involved multiplying (vec4(tcscreen.x, tcScreen.y, depth, 1.0) * 2.0 - 1.0) by the inverse of the projection matrix, dividing the result through by w, then taking the resulting z value as the distance, but this didn't seem to work. What's the correct approach here? Also, when using oblique frustum clipping to shift the near plane onto a chosen clipping plane is the near plane distance now potentially different for every pixel? And if so then does this mean that any shaders that calculate a distance from a depth texture need to be aware of this case and not assume a constant near plane distance? Thanks!
0
0
0
0
1
0
Possible Duplicate: How do you calculate the average of a set of circular data? I have two angles, a=20 degrees and b=350 degrees. The average of those two angles are 185 degrees. However, if we consider that the maximum angle is 360 degrees and allows for wrap around, one could see that 5 degrees is a closer average. I'm having troubles coming up with a good formula to handle that wrap around when calculating average. Anyone got any hints? Or am I shooting myself in the foot here? Is this considered "bad practice" in math?
0
0
0
0
1
0
I have values returned by unknown function like for example # this is an easy case - parabolic function # but in my case function is realy unknown as it is connected to process execution time [0, 1, 4, 9] is there a way to predict next value?
0
0
0
0
1
0
I'm looking for a standalone math equation renderer that generates a gif or png file. It should be able to take equation input from a URL. It has to work on a webserver, preferably on IIS and .NET based. I read the previous topics here, but none of them seem to work well.
0
0
0
0
1
0
Coming from an academic background in mutli-agent systems (developed in Java using JADE) I have only been peripherally aware of the Actor concurrency paradigm. Now that I've started exploring Scala I couldn't help but be struck by the similarities between the Agent and Actor approaches. I'm very tempted to use Scala's Actor library for my next research project rather than simply calling the JADE libraries as this would force me to get to deeper grips with the language. Furthermore JADE's focus on defining everything in terms of behaviours isn't very appropriate to my problem. Is there something fundamentally different between a highly autonomous Actor and an Agent that I am missing?
0
1
0
0
0
0
Is there a publically available library that will produce the exact same results for sin, cos, floor, ceil, exp and log on 32 bit and 64 bit linux, solaris and possibly other platforms? I am considering the following alternatives: a) cephes compiled with gcc -mfpmath=sse and the same optimization levels on each platform ... but its not clear that this would work. b) MPFR but I am worried that this would be too slow. Regarding precision (edited): For this particular application I don't really need something that produces the value that is numerically closest to the exact value. I just need the answers to be the exact same on all platforms, os and "bitness". That being said the values need to be reasonable (5 digits would probably be enough). I apologize for not having made this clear in my initial question. I guess MAPM or MPFR with a low enough precision setting might do the trick but I was hoping to find something that did not have the "multiple precision" machinery/flavor to it. In any case, I will try this out.
0
0
0
0
1
0
Consider a vector V riddled with noisy elements. What would be the fastest (or any) way to find a reasonable maximum element? For e.g., V = [1 2 3 4 100 1000] rmax = 4; I was thinking of sorting the elements and finding the second differential {i.e. diff(diff(unique(V)))}. EDIT: Sorry about the delay. I can't post any representative data since it contains 6.15e5 elements. But here's a plot of the sorted elements. By just looking at the plot, a piecewise linear function may work. Anyway, regarding my previous conjecture about using differentials, here's a plot of diff(sort(V)); I hope it's clearer now. EDIT: Just to be clear, the desired "maximum" value would be the value right before the step in the plot of the sorted elements.
0
0
0
0
1
0
I need to do calculations (division or multiplication) with very large numbers. Currently I am using Double and getting the value round off problems. I can do the same calculations accurately on C# using Decimal type. I am looking for a method to do accurate calculations in VB6.0 and I couldn't find a Decimal type in VB6.0. What is the data type used for doing arithmetic calculations with large values and without getting floating point round off problems?
0
0
0
0
1
0
I feel it is bit curious to understand the Natural language processing. I have the following questions.. What is meant by Scope ambiguity in natural language? How can done Statistical resolution of scope ambiguity? Which is the best language can I use for the Statistical resolution?
0
1
0
0
0
0
Say I have a tile based system using 16x16 pixels. How would you find out what tiles are covered by a rectangle defined by floating point pixel units? for eg, rect(x=16.0,y=16.0, w=1.0, h=1.0) -> tile(x=1, y=1, w=1, h=1) rect(x=16.0,y=16.0, w=16.0, h=16.0) -> tile(x=1, y=1, w=1, h=1) (still within same tile) rect(x=24.0,y=24.0, w=8.0, y=8.0) -> (x=1,y=1,w=1,h=1) (still within same tile) rect(x=24.0,y=24.0, w=8.1, y=8.1) -> (x=1,y=1,w=2,h=2) The only way I can do this reliably is by using a loop. Is there a better way? Dividing by 16 gives me the wrong answer on edge cases. Here's some example code I use in python: #!/usr/bin/env python import math TILE_W = 16 TILE_H = 16 def get_tile(x,y,w,h): t_x = int(x / TILE_W) t_x2 = t_x while t_x2*TILE_W < (x+w): t_x2 += 1 t_w = t_x2-t_x t_y = int( y / TILE_H) t_y2 = t_y while t_y2*TILE_H < (y+h): t_y2 += 1 t_h = t_y2-t_y return t_x,t_y,t_w,t_h (x,y) = 16.0,16.0 (w,h) = 1.0, 1.0 assert get_tile(x,y,w,h) == (1,1,1,1) (x,y) = 16.0,16.0 (w,h) = 15.0, 15.0 assert get_tile(x,y,w,h) == (1,1,1,1) (x,y) = 16.0,16.0 (w,h) = 16.0, 16.0 assert get_tile(x,y,w,h) == (1,1,1,1) (x,y) = 16.0,16.0 (w,h) = 16.1, 16.1 assert get_tile(x,y,w,h) == (1,1,2,2) (x,y) = 24.0, 24.0 (w,h) = 1.0, 1.0 assert get_tile(x,y,w,h) == (1,1,1,1) (x,y) = 24.0, 24.0 (w,h) = 8.0, 8.0 assert get_tile(x,y,w,h) == (1,1,1,1) (x,y) = 24.0, 24.0 (w,h) = 8.1, 8.1 assert get_tile(x,y,w,h) == (1,1,2,2) (x,y) = 24.0, 24.0 (w,h) = 9.0, 9.0 assert get_tile(x,y,w,h) == (1,1,2,2)
0
0
0
0
1
0
I have x,y data coming in from a [coordinates1] database (GIS - but this could be any database). I have my application with it's own coordinate system, referencing THE SAME MAP. I have established that a linear relationship exists between coordinates1 (x,y) and coordinates2(x,y) as I have subtracted two different coordinates1 and coordinates2 (dividing x1 with x2 and y1 with y2) and in all cases I get them both showing 0.724 or 0.141 or 0.825 respectively i.e. coordinates1 + coordinates2. What I now need to figure out - or you help - is that if coordinates1(100000,200000) and coordinates2(0.125,0.255) how do I calculate coordinates2(x,y) from the data in coordinates1(x,y)?
0
0
0
0
1
0
I'm trying to devise a method that will be able to classify a given number of english words into 2 sets - "rare" and "common" - the reference being to how much they are used in the language. The number of words I would like to classify is bounded - currently at around 10,000, and include everything from articles, to proper nouns that could be borrowed from other languages (and would thus be classified as "rare"). I've done some frequency analysis from within the corpus, and I have a distribution of these words (ranging from 1 use, to tops about 100). My intuition for such a system was to use word lists (such as the BNC word frequency corpus, wordnet, internal corpus frequency), and assign weights to its occurrence in one of them. For instance, a word that has a mid level frequency in the corpus, (say 50), but appears in a word list W - can be regarded as common since its one of the most frequent in the entire language. My question was - whats the best way to create a weighted score for something like this? Should I go discrete or continuous? In either case, what kind of a classification system would work best for this? Or do you recommend an alternative method? Thanks! EDIT: To answer Vinko's question on the intended use of the classification - These words are tokenized from a phrase (eg: book title) - and the intent is to figure out a strategy to generate a search query string for the phrase, searching a text corpus. The query string can support multiple parameters such as proximity, etc - so if a word is common, these params can be tweaked. To answer Igor's question - (1) how big is your corpus? Currently, the list is limited to 10k tokens, but this is just a training set. It could go up to a few 100k once I start testing it on the test set. 2) do you have some kind of expected proportion of common/rare words in the corpus? Hmm, I do not.
0
0
0
0
1
0
My Taglist in a C code: macro || MIN_LEN || MAX_ITERATIONS ||- typedef || cell || source_cell ||- variable || len_given Taglist elements (domain): A = {MIN_LEN, MAX_ITERATIONS, cell, source_cell, len_given} Code snippets (codomain): B = {"code_MIN_LEN", "code_MAX_ITERATIONS", ..., "code_len_given"} Goal: to have bijection between the sets A and B. Example: I want to remove any element in A, such as the MIN_LEN, from A and B by removing either its element in A or B. Question: Is there a way to quarantee a bijection between A and B so that a change either in A or in B results in a change in the other set?
0
0
0
0
1
0
On the iPhone, I get the user's location in decimal degrees, for example: latitude 39.470920 and longitude = -0.373192; That's point A. I need to create a line with another GPS coordinate, also in decimal degrees, point B. Then, calculate the distance (perpendicular) between the line from A to B and another point C. The problem is I get confused with the values in degrees. I would like to have the result in meters. What's the conversion needed? How will the final formula to compute this look like?
0
0
0
0
1
0
I wonder if it is possible (and if it is then how) to re-present an arbitrary M3 matrix transformation as a sequence of simpler transformations (such as translate, scale, skew, rotate) In other words: how to calculate MTranslate, MScale, MRotate, MSkew matrices from the MComplex so that the following equation would be true: MComplex = MTranslate * MScale * MRotate * MSkew (or in an other order)
0
0
0
0
1
0
I need to implement an inverted beta function in MySQL (similar to Excel's BETAINV). There is some related material is available on Wolfram MathWorld's Beta Distribution page. Any clues on where to start implementing this functionality in MySQL?
0
0
0
0
1
0
The code golf series seem to be fairly popular. I ran across some code that converts a number to its word representation. Some examples would be (powers of 2 for programming fun): 2 -> Two 1024 -> One Thousand Twenty Four 1048576 -> One Million Forty Eight Thousand Five Hundred Seventy Six The algorithm my co-worker came up was almost two hundred lines long. Seems like there would be a more concise way to do it. Current guidelines: Submissions in any programming language welcome (I apologize to PhiLho for the initial lack of clarity on this one) Max input of 2^64 (see following link for words, thanks mmeyers) Short scale with English output preferred, but any algorithm is welcome. Just comment along with the programming language as to the method used.
0
1
0
0
0
0
There are a few questions around that circle around this question but I feel this is different enough. I've decided I want to improve the breadth and depth of my maths skills specifically in areas that are useful and/or interesting to programmers. What topics should I study? What resources do you recommend (blogs/books/online lectures...)? I'm looking for easy to consume resources because I'll be doing this in my free time, I don't want to spend days struggling through a dense text but I want to get deeper than the surface. I've read the Yegge article on the topic (and most of the comments) which is useful but I think the voting system here will help me focus on the most useful/best resources and topics. Edit: I am looking to create myself a study course that I'll follow over the next few years, I'm not looking to solve a particular problem I just want to learn some new skills that will interest me and may be useful in my career in the future.
0
0
0
0
1
0
This is a purely math question, I believe. I have a camera object in an arbitrary coordinate system. I have the direction vector of the camera, and I have a vector that points in the direction of north along the surface of the sphere. I wish to calculate the angle of the camera in regards to the north vector. Is there a simple way to calculate the final sign of the angle? I'm aware than angle = acos(dir dot north), but when I implement it, the angle is clamped to [0,180] degrees. Is there a way to figure out whether the camera is painting eastward or not?
0
0
0
0
1
0
I understand that it's from 0 to rows and from 1 to rows, but which is including and which is excluding?
0
0
0
0
1
0
So I have a bunch of hyperlinks on a web page. From past observation I know the probabilities that a user will click on each of these hyperlinks. I can therefore calculate the mean and standard deviation of these probabilities. I now add a new hyperlink to this page. After a short amount of testing I find that of the 20 users that see this hyperlink, 5 click on it. Taking into account the known mean and standard deviation of the click-through probabilities on other hyperlinks (this forms a "prior expectation"), how can I efficiently estimate the probability of a user clicking on the new hyperlink? A naive solution would be to ignore the other probabilities, in which case my estimate is just 5/20 or 0.25 - however this means we are throwing away relevant information, namely our prior expectation of what the click-through probability is. So I'm looking for a function that looks something like this: double estimate(double priorMean, double priorStandardDeviation, int clicks, int views); I'd ask that, since I'm more familiar with code than mathematical notation, that any answers use code or pseudocode in preference to math.
0
0
0
0
1
0
I require to do a project as a part of my final year of engineering graduation studies.Can you suggest some projects pertaining to distributed systems and artificial intelligence together and which require python,c or c++ for programming? Note:-Please suggest a project that is attainable for a group of 2 students.
0
1
0
0
0
0
I have an SVM in R and I would now like to plot the classification space for this machine. I have found some examples on the Internet, but I can't seem to make sense of them. My R script is as follows: library(e1071) day_of_week <- c(0,1,2,3,4,5,6) holiday <- factor( c(T, F, F, F, F, F, T) ) model <- svm(day_of_week, holiday) plot(model, day_of_week, holiday) I cannot get the plot command to work. I would like a graph something like this http://bm2.genes.nig.ac.jp/RGM2/R_current/library/e1071/man/images/plot.svm_001.png
0
0
0
1
0
0
Are integers in C assumed to be handled by a hardware spec or handled in software? By integer, I am referring to the primitive "int" The underlying idea being that if integers in C are not hardware dependent would it be a violation of standard to have gcc implement different integer handlers. This way you could have your traditional 32 bit int handler, and then you could also have handlers for 256 bit integers, or maybe even dynamic sized ints. I do know about long and long long, but I'm not sure if those are independent of that hardware provided, and I'd like to just specify the size/type of "int" handler to use when building a toolchain. I also understand the dangers of doing this (because building building 256 bit integers with a 32 bit integer compiler would be bad!), but for those bits of code that require something like a gmp library, I think it would make code readability much better. Compatibility would be the same but the dependency would be on the compiler instead of the code itself. Crazy idea, I know... but back to the original question: Are integers in C assumed to be handled by a hardware spec or handled in software?
0
0
0
0
1
0
I have a database, consisting of a whole bunch of records (around 600,000) where some of the records have certain fields missing. My goal is to find a way to predict what the missing data values should be (so I can fill them in) based on the existing data. One option I am looking at is clustering - i.e. representing the records that are all complete as points in some space, looking for clusters of points, and then when given a record with missing data values try to find out if there are any clusters that could belong in that are consistent with the existing data values. However this may not be possible because some of the data fields are on a nominal scale (e.g. color) and thus can't be put in order. Another idea I had is to create some sort of probabilistic model that would predict the data, train it on the existing data, and then use it to extrapolate. What algorithms are available for doing the above, and is there any freely available software that implements those algorithms (This software is going to be in c# by the way).
0
0
0
0
1
0
I am currently reading the Algorithm Design Manual, but my mathematical notation has become a little rusty. What does mean?
0
0
0
0
1
0
The Problem: A box can hold 53 items. If a person has 56 items, it will require 2 boxes to hold them. Box 1 will hold 53 items and box 2 will hold 3. How do I repeat the above where 53 is a constant, unchanging, value and 56 is a variable for each box: Math.Ceiling(Convert.ToDecimal(intFeet / 53)) what I have so far for that is: int TotalItems = 56; int Boxes = Math.Ceiling(Convert.ToDecimal(intFeet / 53)); for (int i = 0; i < Boxes; i++) { int itemsincurrentbox=?? }
0
0
0
0
1
0
I have been asked to program a routine to decide the number of possible combinations in a product configurator. The configurator is really simple. Even though it has more features than this, it can be modeled as several "radio groups" (like the UI control) where one of n options has to be selected. The only kind of constraints that can be used is rules that says if one option is selected another option can not be selected. So what I want to do is to calculate the number of different products that can be configured, given a set of option groups and constraints. I made a naive approach to solve this using the Inclusion-exclusion principle. However as far as I can see, any algorithm based on this method should run in O(2^n) which won't work. There are of course several possible optimizations that should give decent runtimes but there are still easily constructed worst case scenarios. Thats pretty much where I am right now. Any suggestions? Update I realize I haven't explained how the rules applies well enough. There are several groups with options. One and only one option must be selected in each group. There can be one or more of options in a group. There is only one type of constraints. If option A in some group is selected, then option B in some other group can't be selected. There can be any number of constraints, there is no limit how many constraints/rules apply to a option group or an option itself. So an example would be: Group 1: x1 x2 x3 x4 x5 Group 2: y1 y2 y3 Group 3: z1 z2 z3 z4 Constraints: x1 <-> y2 * x1 <-> z4 y2 <-> z2 * If option x1 is selected in group1, then option y2 in group 2 can not be selected. Using inclusion-exclusion I would calculate the number of combinations as Combinations = Cno rules - Cr[1] - Cr[2] - Cr[3] + Cr[1,2] + Cr[1,3] + Cr[2,3] - Cr[1,2,3] Where Cno rules = 5 * 3 * 4 Cr[a,b,c] = Number of combinations that violates rule a, b and c. The method unfortunately requires 2^|rules| calculations.
0
0
0
0
1
0
I am currently looking for a programming language to write a math class in. I know that there are lots and lots of them everywhere around, but since I'm going to start studying math next semester, I thought this might be a good way to get a deeper insight in to what I've learned. Thanks for your replys. BTW: If you are wondering what I wanted to ask: "Is there a strongly typed programming language which allows you to define new operators?"
0
0
0
0
1
0
Is it possible to find out whether one drawing line (which is not in a horizontal or vertical position) overlapped (or touched) any other items (like line, rectangle, circle etc). Kindly advise me on the possibilities and solution with examples. Thanks for looking into this...
0
0
0
0
1
0
Is there a way, given a set of values (x,f(x)), to find the polynomial of a given degree that best fits the data? I know polynomial interpolation, which is for finding a polynomial of degree n given n+1 data points, but here there are a large number of values and we want to find a low-degree polynomial (find best linear fit, best quadratic, best cubic, etc.). It might be related to least squares... More generally, I would like to know the answer when we have a multivariate function -- points like (x,y,f(x,y)), say -- and want to find the best polynomial (p(x,y)) of a given degree in the variables. (Specifically a polynomial, not splines or Fourier series.) Both theory and code/libraries (preferably in Python, but any language is okay) would be useful.
0
0
0
0
1
0
What equation is needed to move a point on an isometric plane in a 2d space? I've looked several places on the tubes. Mostly here. and I haven't been able to decipher it. I'm not a math major, unfortunately. What I need to do is move a point from (0,0) to (1,0) or (0,1) on an isometric plane consisting of 10px blocks. In normal-ville I would just do (x+10, y+0) or (x+0, y+10) to move myself on my 2d plane. I do most of my work in Core Animation on the iPhone if that gives a better context. Thank you for your time. DP
0
0
0
0
1
0
In information retrieval, the words in the documents were represented as a "Term Vector", they did it primarily to check the angle between two vectors. When have you represented something as a vector in your work and what is the common heuristic that you use to represent an entity as a vector?
0
0
0
0
1
0
I need to show natural dates like "few seconds ago" "21 minutes ago" Is there something built in to the rails? Or may be third party? This is not hard to implement, but I do not want to invent the wheel.
0
1
0
0
0
0
I have a program written in C# and some parts are writing in native C/C++. I use doubles to calculate some values and sometimes the result is wrong because of too small precision. After some investigation i figured out that someone is setting the floating-point precision to 24-bits. My code works fine, when i reset the precision to at least 53-bits (using _fpreset or _controlfp), but i still need to figure out who is responsible for setting the precision to 24-bits in the first place. Any ideas who i could achieve this?
0
0
0
0
1
0
I'm looking for a formula that can spread out numbers in a linear format based on a minimum number, max number and amount of numbers (or dots) between. The catch is, the closer you get to the max, the more numbers should be there. An example (number will vary and will be about 100 times larger) Min = 0 Max = 16 AmountOfNumbersToSpread = 6 0 1 2 3 4 5 6 7 8 9 A B C D E F 1 2 3 4 5 6 Thanks for the help in advance.
0
0
0
0
1
0
Is there C++ template class that implements operations with permutations and permutation group? Such class has to implement finding product and inverse, multiplication, etc.
0
0
0
0
1
0
We would like to include a facility in an ASP.NET web application that will allow a user to type in a natural language (or reasonably close to natural) question about a SQL data set (SQL Server) and get useful information in return. The sort of results required is to include min, max, std deviation, top 10, total for a column, and anything else that makes sense with a bunch of numbers. What are the tools that are available for this sort of operation, and what are the considerations that we should be aware of?
0
1
0
0
0
0
Are there any serious scientific math libraries made with functional programming languages? From the very nature of functional languages one would think that they are particularly suitable for math, but yet the well-known algorithms seem to be procedural. For instance, the classic Numerical Recipes series is written pretty much in procedural way. LAPACK is almost de facto standard in many fields, but it's in Fortran and thus procedural or maybe OO, but definitely not functional. Has anyone been able to transfer these kinds of well-known procedural algorithms to functional style? Update: it seems to be so that functional languages are being used in symbolic calculations, e.g. in Mathematica. But, is there something inherently incompatible with numeric calculations and functional algorithms? Or is it just so that because imperative algorithms happened to be invented first, nobody has bothered to come up with functional equivalents?
0
0
0
0
1
0
Could any of you experienced programmers / ethical hackers out there recommend some blogs or books on security/encryption? The only blogs I look at now are, .Net Security Blog. Laptop Security Blog. Schneier On Security. I am especially interested in the mathematical theory behind the security/encryption, not just how to use it.
0
0
0
0
1
0
I want to crawl for specific things. Specifically events that are taking place like concerts, movies, art gallery openings, etc, etc. Anything that one might spend time going to. How do I implement a crawler? I have heard of Grub (grub.org -> Wikia) and Heritix (http://crawler.archive.org/) Are there others? What opinions does everyone have? -Jason
0
1
0
0
0
0
I'm trying to put together an app for fun that has a scenario where I need to figure out a probability equation for the following scenario: Suppose I have a number of attempts at something and each attempt has a success rate (known ahead of time). What are the odds after doing all those attempts that a success happens? For example there are three attempts (all will be taken individually). The first is known to have a 60% success rate. The second is known to have a 30% success rate. The third is known to have a 75% success rate. What are the odds of a success occurring if all three attempts are made? I've tried several formulas and can't pinpoint the correct one. Thanks for the help!
0
0
0
0
1
0
Take the following C code (K&R pg. 77) : push(pop() - pop()); /* WRONG */ The book says that since - and / are not commutative operators, the order in which the 2 pop functions are evaluated is necessary (obviously, to get the correct result)...and thus you have to put the result of the first function in a variable first and then proceed with the arithmetic, like such: op2 = pop(); push(op2 - pop()); Apparently this is because the compiler can't guarantee in which order the functions are evaluated (...why?) My question is, does C# do this same thing? as in, do I have to worry about this sort of thing when working with C# ? and for that matter, any of the other higher level languages ?
0
0
0
0
1
0
I have 4 points that form some quadrilateral. The lines can't cross or anything like that, it should be a square, rectangle, rhombus, parallelogram, etc. The lines that connect them break the field into 9 regions. With a square, it would look like a tic-tac-toe board (#), but with other shapes the lines will be at angles. A point falls randomly into this 9-region field. I know the coordinates of the random point, as well as the coordinates of the quadrilateral's 4 corners. Is there any way I can find which field contains the point without using the equations of the lines? I'm basically looking for something like if(p.x > q1.x && p.x < q4.x && p.y < q3.y) { //It's in the top left region } etc I'm thinking that this isn't possible when using sloped lines (rather than a square/rectangle) without solving the line equations. But I thought I'd run it by the math guys first. THANKS!
0
0
0
0
1
0
What is a good way to implement Gaussian elimination when the operators are custom operators, rather then standard arithmetic ones? Here are the operators: Addition: 0 + 0 = 0 0 + 1 = 1 1 + 1 = 0 Subtraction: 0 - 0 = 0 0 - 1 = 1 1 - 1 = 0 Multiplication: 0 * 0 = 0 0 * 1 = 0 1 * 1 = 1 Division: 0 / 0 = illegal 0 / 1 = 0 1 / 1 = 1 Here is a sample set of equations as augmented matrix, with the RHS in the right-most column: 1, 1, 0, 1, 0, 0, 0, 0, 0, 1 0, 1, 0, 1, 1, 0, 0, 0, 0, 1 0, 1, 1, 0, 0, 1, 0, 0, 0, 1 1, 0, 0, 1, 0, 0, 0, 0, 0, 1 0, 1, 0, 1, 1, 0, 0, 0, 0, 1 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 0, 0, 0, 1, 0, 0, 1, 0, 0, 1 0, 0, 0, 1, 1, 0, 1, 1, 0, 1 0, 0, 0, 0, 0, 1, 0, 0, 1, 1 The solution for this set is: x1 = 1 x2 = 0 x3 = 0 x4 = 0 x5 = 1 x6 = 1 x7 = 1 x8 = 1 x9 = 0 Gaussian elimination failed for me as I tried it on this set. The equations will have 9, 16, 25 or 36 terms. It would be great if the algorithm is easily extendable to larger squares, up to 100. I'm looking for an algorithm, in pseudo code or JavaScript preferably.
0
0
0
0
1
0
There are phonetic level, syntactic level, semantic level, phonological level, acoustic level, linguistic level, language level. Are there any other levels? What's the order from the bottom up? And what are they really about?
0
1
0
0
0
0
I have to write a program to solve quadratics, returning a complex number result. I've gotten so far, with defining a complex number, declaring it to be part of num, so +,- and * - ing can take place. I've also defined a data type for a quadratic equation, but im now stuck with the actual solving of the quadratic. My math is quite poor, so any help would be greatly appreciated... data Complex = C { re :: Float, im :: Float } deriving Eq -- Display complex numbers in the normal way instance Show Complex where show (C r i) | i == 0 = show r | r == 0 = show i++"i" | r < 0 && i < 0 = show r ++ " - "++ show (C 0 (i*(-1))) | r < 0 && i > 0 = show r ++ " + "++ show (C 0 i) | r > 0 && i < 0 = show r ++ " - "++ show (C 0 (i*(-1))) | r > 0 && i > 0 = show r ++ " + "++ show (C 0 i) -- Define algebraic operations on complex numbers instance Num Complex where fromInteger n = C (fromInteger n) 0 -- tech reasons (C a b) + (C x y) = C (a+x) (b+y) (C a b) * (C x y) = C (a*x - b*y) (b*x + b*y) negate (C a b) = C (-a) (-b) instance Fractional Complex where fromRational r = C (fromRational r) 0 -- tech reasons recip (C a b) = C (a/((a^2)+(b^2))) (b/((a^2)+(b^2))) root :: Complex -> Complex root (C x y) | y == 0 && x == 0 = C 0 0 | y == 0 && x > 0 = C (sqrt ( ( x + sqrt ( (x^2) + 0 ) ) / 2 ) ) 0 | otherwise = C (sqrt ( ( x + sqrt ( (x^2) + (y^2) ) ) / 2 ) ) ((y/(2*(sqrt ( ( x + sqrt ( (x^2) + (y^2) ) ) / 2 ) ) ) ) ) -- quadratic polynomial : a.x^2 + b.x + c data Quad = Q { aCoeff, bCoeff, cCoeff :: Complex } deriving Eq instance Show Quad where show (Q a b c) = show a ++ "x^2 + " ++ show b ++ "x + " ++ show c solve :: Quad -> (Complex, Complex) solve (Q a b c) = STUCK! EDIT: I seem to have missed out the whole point of using my own complex number datatype is to learn about custom datatypes. I'm well aware that i could use complex.data. Any help that could be given using my solution so far would be greatly appreciated.\ EDIT 2: It seems that my initial question was worded horribly. I'm aware that the quadratic formula will return both (or just the one) root to me. Where I am having trouble is returning these roots as a (complex, complex) tuple with the code above. I'm well aware that I could use the built in quadratic functions as have been displayed below, but this is not the exercise. The idea behind the exercise, and creating ones own complex number data type, is to learn about custom data types.
0
0
0
0
1
0
Allright - seems my question was as cloudy as my head. Lets try again. I have 3 properties while configuring viewports for a D3D device: - The resolution the device is running in (full-screen). - The physical aspect ratio of the monitor (as fraction and float:1, so for ex. 4:3 & 1.33). - The aspect ratio of the source resolution (source resolution itself is kind of moot and tells us little more than the aspect ratio the rendering wants and the kind of resolution that would be ideal to run in). Then we run into this: // -- figure out aspect ratio adjusted VPs -- m_nativeVP.Width = xRes; m_nativeVP.Height = yRes; m_nativeVP.X = 0; m_nativeVP.Y = 0; m_nativeVP.MaxZ = 1.f; m_nativeVP.MinZ = 0.f; FIX_ME // this does not cover all bases -- fix! uint xResAdj, yResAdj; if (g_displayAspectRatio.Get() < g_renderAspectRatio.Get()) { xResAdj = xRes; yResAdj = (uint) ((float) xRes / g_renderAspectRatio.Get()); } else if (g_displayAspectRatio.Get() > g_renderAspectRatio.Get()) { xResAdj = (uint) ((float) yRes * g_renderAspectRatio.Get()); yResAdj = yRes; } else // == { xResAdj = xRes; yResAdj = yRes; } m_fullVP.Width = xResAdj; m_fullVP.Height = yResAdj; m_fullVP.X = (xRes - xResAdj) >> 1; m_fullVP.Y = (yRes - yResAdj) >> 1; m_fullVP.MaxZ = 1.f; m_fullVP.MinZ = 0.f; Now as long as g_displayAspectRatio equals the ratio of xRes/yRes (= adapted from device resolution), all is well and this code will do what's expected of it. But as soon as those 2 values are no longer related (for example, someone runs a 4:3 resolution on a 16:10 screen, hardware-stretched) another step is required to compensate, and I've got trouble figuring out how exactly. (and p.s I use C-style casts on atomic types, live with it :-) )
0
0
0
0
1
0
So I have finished creating my own complex number data type in haskell. I've also, thanks to another question on here, got a function that will solve a quadratic equation. The only problem now is that the code generates a parsing error in hugs, when trying to solve a quadratic with complex roots. i.e. In hugs... Main> solve (Q 1 2 1) (-1.0,-1.0) Main> solve (Q 1 2 0) (0.0,-2.0) Main> solve (Q 1 2 2) ( Program error: pattern match failure: v1618_v1655 (C -1.#IND -1.#IND) It looks to my like its a problem after the square-root has been applied, but I'm really not sure. Any help trying to pick up what is going wrong or any indications as to what this error means would be brilliant. Thanks, Thomas The Code: -- A complex number z = (re +im.i) is represented as a pair of Floats data Complex = C { re :: Float, im :: Float } deriving Eq -- Display complex numbers in the normal way instance Show Complex where show (C r i) | i == 0 = show r | r == 0 = show i++"i" | r < 0 && i < 0 = show r ++ " - "++ show (C 0 (i*(-1))) | r < 0 && i > 0 = show r ++ " + "++ show (C 0 i) | r > 0 && i < 0 = show r ++ " - "++ show (C 0 (i*(-1))) | r > 0 && i > 0 = show r ++ " + "++ show (C 0 i) -- Define algebraic operations on complex numbers instance Num Complex where fromInteger n = C (fromInteger n) 0 -- tech reasons (C a b) + (C x y) = C (a+x) (b+y) (C a b) * (C x y) = C (a*x - b*y) (b*x + b*y) negate (C a b) = C (-a) (-b) instance Fractional Complex where fromRational r = C (fromRational r) 0 -- tech reasons recip (C a b) = C (a/((a^2)+(b^2))) (b/((a^2)+(b^2))) root :: Complex -> Complex root (C x y) | y == 0 && x == 0 = C 0 0 | y == 0 && x > 0 = C (sqrt ( ( x + sqrt ( (x^2) + 0 ) ) / 2 ) ) 0 | otherwise = C (sqrt ( ( x + sqrt ( (x^2) + (y^2) ) ) / 2 ) ) ((y/(2*(sqrt ( ( x + sqrt ( (x^2) + (y^2) ) ) / 2 ) ) ) ) ) -- quadratic polynomial : a.x^2 + b.x + c data Quad = Q { aCoeff, bCoeff, cCoeff :: Complex } deriving Eq instance Show Quad where show (Q a b c) = show a ++ "x^2 + " ++ show b ++ "x + " ++ show c solve :: Quad -> (Complex, Complex) solve (Q a b c) = ( sol (+), sol (-) ) where sol op = (op (negate b) $ root $ b*b - 4*a*c) / (2 * a)
0
0
0
0
1
0
Im trying to create a easy sine curv in SQL which alternates between the values (0-23). I have the following variables: x, which is the current offset. y which is the destinated offset, and z which is my max value(23). Anyone that could help me with the expression? Have googled and read about it, but havent got it to work yet.. Would be greatful for any answers.. Best Regards, Tom
0
0
0
0
1
0
I was adding a Fraction class to my codebase the other day (the first time, never needed one before and I doubt I do now, but what the hell :-)). When writing the addition between two fractions, I found a small optimization but it doesn't make sense (in the mathematical sense) why it is like it is. To illustrate I will use fractions A and B, effecively consisting of An, Bn, Ad and Bd for numerator and denominator respectively. Here are two functions I use for GCD/LCM, the formulas are on Wikipedia as well. They're simple enough to understand. The LCM one could just as well be (A*B)/C of course. static unsigned int GreatestCommonDivisor(unsigned int A, unsigned int B) { return (!B) ? A : GreatestCommonDivisor(B, A % B); } static unsigned int LeastCommonMultiple(unsigned int A, unsigned int B) { const unsigned int gcDivisor = GreatestCommonDivisor(A, B); return (A / gcDivisor) * B; } First lets go around the 1st approach: least_common_mul = least_common_multiple(Ad, Bd) new_nominator = An * (least_common_mul / Ad) + Bn * (least_common_mul / Bd) new_denominator = least_common_mul Voila, works, obvious, done. Then through some scribbling on my notepad I came across another one that works: greatest_common_div = greatest_common_divisor(Ad, Bd) den_quot_a = Ad / greatest_common_div den_quot_b = Bd / greatest_common_div new_numerator = An * den_quot_b + Bn * den_quot_a new_denominator = den_quot_a * Bd Now the new denominator is fairly obvious, as it's exactly the same as happens in the LCD function. The other ones seem to make sense too, except for that the the right factors to multiply the original numerators with are swapped, in this line to be specific: new_numerator = An * den_quot_b + Bn * den_quot_a Why is that not AA + BB? Input example: 5/12 & 11/18 greatest_common_div = 6 den_quot_a = 12/6 = 2; den_quot_b = 18/6 = 3; new_numerator = 5*3 + 11*2 = 37; new_denominator = 36;
0
0
0
0
1
0
What is the algorithm - seemingly in use on domain parking pages - that takes a spaceless bunch of words (eg "thecarrotofcuriosity") and more-or-less correctly breaks it down into the constituent words (eg "the carrot of curiosity") ?
0
1
0
0
0
0
I have an image that I want to be watermarked to the bottom right section of other images. The dimensions of the watermark image are 179 width, 39 height. Now what if I have another image whose dimensions are 150 width, 20 height? If we tried to watermark it using the original image, it would obviously be too large and the image itself would be masked completely by the watermark image, right? So how can I determine a smaller width and height to which I will resize the watermark image, something much less than 150 width, 20 height, so that it will appear still as a watermark and wont mask the image completely?
0
0
0
0
1
0
How to use Wordnet in SQL database. Does it exists anywhere can someone give me step by step procedure
0
1
0
0
0
0
I know there must be a generic method but I don't even know the term to search for and I don't want to re-invent the wheel, badly. 'Separate components values' and 'composite values' don't give good results. another example: degrees+minutes+seconds from seconds of arc, or tons+pounds+ounces from ounces. I'm working in C but it shouldn't be too hard to translate from some other language. The inputs would be the basic value, say total inches= 9534567, and the unit divisions, like feet=12, yards=feet*3, miles=yards*1760. The output would be 150 miles, 849 yards, 0 feet and 3 inches. Surely this can be generalized to use some other set of unit divisions. And a whole library seems like overkill, doesn't it?
0
0
0
0
1
0
I actually have it done, I did this math equation about 2 years ago and I am having trouble understanding it now. Basicly I use this so that when users upload photos to my site, I can balance them out with only X amount of photo per folder. This gives me something like this 1/1 1/2 1/3 1/4 ----1/10 2/1 2/2 2/3 and so on but I need to modify it to go 3 folders deep, each folder should have a limit of the number 1-9 or 1-10 then it will increase that number to the next So if a large enough number is entered into my function below and the result is 3/10 then when the right number of objects is reached it would bump up to 4/1 then when so many thousands objects go by again it will jump to 4/2. What I am wanting to do is make it 3 numbers/levels deep 3/10/2 would go to 3/10/3 when it got to 3/10/10 it would go 4/1/1 4/1/2 4/1/3 when the third place got to 10 it would make it got to 4/2/1 <?PHP function uploadfolder($x) { $dir = floor($x/18001) + 1; $sdir = ceil($x/2000) % 9; return "$dir/$sdir"; } ?> I spent a lot of time 2 years ago to get it to do this with 2 levels deep and I just kind of got lucky and now it is somewhat confusing for me looking back at it
0
0
0
0
1
0
How do I find the side length of a cross-section (as illustrated in the drawing below - cross-section in red) of a pyramid frustum/truncated pyramid? I know the side-lengths of the top and bottom base, the height of the frustum and the distance to the cross-section. Furthermore I know the top and bottom base are parallel and that the center of the top and bottom base are directly on top of each other.
0
0
0
0
1
0
(Also posted on the MSDN forum - but that doesn't get much traffic, as far as I can see.) I've been trying to provide an example of Assert and Assume. Here's the code I've got: public static int RollDice(Random rng) { Contract.Ensures(Contract.Result<int>() >= 2 && Contract.Result<int>() <= 12); if (rng == null) { rng = new Random(); } Contract.Assert(rng != null); int firstRoll = rng.Next(1, 7); Contract.Assume(firstRoll >= 1 && firstRoll <= 6); int secondRoll = rng.Next(1, 7); Contract.Assume(secondRoll >= 1 && secondRoll <= 6); return firstRoll + secondRoll; } (The business about being able to pass in a null reference instead of an existing Random reference is purely pedagogical, of course.) I had hoped that if the checker knew that firstRoll and secondRoll were each in the range [1, 6], it would be able to work out that the sum was in the range [2, 12]. Is this an unreasonable hope? I realise it's a tricky business, working out exactly what might happen... but I was hoping the checker would be smart enough :) If this isn't supported now, does anyone here know if it's likely to be supported in the near-ish future? EDIT: I've now found that there are very complicated options for arithmetic in the static checker. Using the "advanced" text box I can try them out from Visual Studio, but there's no decent explanation of what they do, as far as I can tell.
0
0
0
0
1
0