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
|
|---|---|---|---|---|---|---|
Background: I have a bird view's JavaScript game where the player controls a space ship by touching a circle -- e.g. touch to the left of the circle center, and the ship will move left, touch the top right and it will move to the top right and so on... the further away from the circle center of pseudo joystick, the more speed in that direction. However, I'm not directly adjusting the ship's speed, but rather set a targetSpeed.x and targetSpeed.y value, and the ship will then adjust its speed using something like:
if (this.speed.x < this.targetSpeed.x) {
this.speed.x += this.speedStep;
}
else if (this.speed.x > this.targetSpeed.x) {
this.speed.x -= this.speedStep;
}
... and the same for the y speed, and speedStep is a small value to make it smoother and not too abrupt (a ship shouldn't go from a fast leftwards direction to an immediate fast rightwards direction).
My question: Using above code, I believe however that the speed will be adjusted quicker in diagonal directions, and slower along the horizontal/ vertical lines. How do I correct this to have an equal target speed following?
Thanks so much for any help!
| 0
| 0
| 0
| 0
| 1
| 0
|
In a simple way, i have an array of 10 values for example..and i would like to multiply each value with 5. Can i actually just do the following?
for (i = 0 ; i <10 ; i++)
{
x[i]=x[i]*5;
}
And what about getting square for values in the array and be stored back into the same array? As in I want x[i]=x[i]*x[i].
Can I actually just do the multiplication like that?
I tried a couple of combination but it didnt really work..hope someone can help out! Thanks!
| 0
| 0
| 0
| 0
| 1
| 0
|
Let's say I have an increasing sequence of integers: seq = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4 ... ] not guaranteed to have exactly the same number of each integer but guaranteed to be increasing by 1.
Is there a function F that can operate on this sequence whereby F(seq, x) would give me all 1's when an integer in the sequence equals x and all other integers would be 0.
For example:
t = [1, 1, 1, 1, 2, 2, 3, 3, 3, 4]
F(t, 2) = [0, 0, 0, 0, 1, 1, 0, 0, 0, 0]
EDIT: I probably should have made it more clear. Is there a solution where I can do some algebraic operations on the entire array to get the desired result, without iterating over it?
So, I'm wondering if I can do something like: F(t, x) = t op x ?
In Python (t is a numpy.array) it could be:
(t * -1) % x or something...
EDIT2: I found out that the identity function I(t[i] == x) is acceptable to use as an algebraic operation. Sorry, I did not know about identity functions.
| 0
| 0
| 0
| 0
| 1
| 0
|
I am using the Apache Commons math.Fraction class to convert my doubles to fractions, which is working fine.
However, I need it to calculate these fractions in a way that makes sense for displaying lengths in inches, to the nearest 1/32".
For example, converting 0.325 to a fraction yields 12/37, which doesn't make sense to someone looking at a US ruler. I suppose I want to round the decimal to the nearest .03125 before i convert it, if that makes sense. My basic math skills are failing me :(
edit
To clarify, all the input is in decimal inches between 0 and 1. Given the sample input above, I would want 5/16".
| 0
| 0
| 0
| 0
| 1
| 0
|
Background: I have 8 images for every sprite in my bird's view JavaScript game, representing top, top-right, right, right-bottom etc., depending on the player's space ship speed.
Question: Given the values sprite.speed.x and sprite.speed.y (which could be something like 4 and -2.5, or 2 and 0 for instance), how do I get the correct angle in degrees? Given that angle, I could then have a lookup for which degrees value represents which sprite image. Or perhaps there's an even easier way. (Currently I'm just using something like "if x below zero use left image" etc. which will result in diagonal images used almost all of the time.)
Searching around, I found ...
angle = Math.atan2(speed.y, speed.x);
... but somehow I'm still missing something.
PS: Zero speed can be ignored, these sprites will just use whatever was the last valid direction image.
Thanks so much for any help!
| 0
| 0
| 0
| 0
| 1
| 0
|
Sorry if this doesn't make sense... I know the length of the triangle segments and the xy coordinates of two points. How do I figure out the xy of the 3rd point?
| 0
| 0
| 0
| 0
| 1
| 0
|
I recently was part of a small java programming competition at my school. My partner and I have just finished our first pure oop class and most of the questions were out of our league so we settled on this one (and I am paraphrasing somewhat): "given an input integer n return the next int that is prime and its reverse is also prime for example if n = 18 your program should print 31" because 31 and 13 are both prime. Your .class file would then have a test case of all the possible numbers from 1-2,000,000,000 passed to it and it had to return the correct answer within 10 seconds to be considered valid.
We found a solution but with larger test cases it would take longer than 10 seconds. I am fairly certain there is a way to move the range of looping from n,..2,000,000,000 down as the likely hood of needing to loop that far when n is a low number is small, but either way we broke the loop when a number is prime under both conditions is found. At first we were looping from 2,..n no matter how large it was then i remembered the rule about only looping to the square root of n. Any suggestions on how to make my program more efficient? I have had no classes dealing with complexity analysis of algorithms. Here is our attempt.
public class P3
{
public static void main(String[] args){
long loop = 2000000000;
long n = Integer.parseInt(args[0]);
for(long i = n; i<loop; i++)
{
String s = i +"";
String r = "";
for(int j = s.length()-1; j>=0; j--)
r = r + s.charAt(j);
if(prime(i) && prime(Long.parseLong(r)))
{
System.out.println(i);
break;
}
}
System.out.println("#");
}
public static boolean prime(long p){
for(int i = 2; i<(int)Math.sqrt(p); i++)
{
if(p%i==0)
return false;
}
return true;
}
}
ps sorry if i did the formatting for code wrong this is my first time posting here. Also the output had to have a '#' after each line thats what the line after the loop is about Thanks for any help you guys offer!!!
| 0
| 0
| 0
| 0
| 1
| 0
|
Maybe this is just impossible and I should give up all hope. Or maybe there's a really clever way to do it that I haven't thought of.
Here's two examples of what I've got:
يَبِسَ - يَيْبَسُ (yabisa,
yaybasu)[y-b-s][ي-ب-س] (To become dry,
stiff, rigid) 20:77 yabasan = dry.
يَسَّرَ - يُيَسِّرُ (yassara,
yuyassiru)[y-s-r][ي-س-ر] (To
facilitate, make it easy) 92:7
nuyassiruhuu = We will ease him.
and
Zu Hülfe! zu Hülfe! Help! Help!
Sonst bin ich verloren! Otherwise I am
lost! Zu Hülfe! Zu Hülfe! Help!
Help! Sonst bin ich
verloren! Otherwise I am lost! Der
listigen Schlange zum Opfer erkoren,
Selected as offering to the cunning
snake, Barmherzigige Götter! Merciful
Gods! Schon nahet sie sich, Already it
gets closer, Schon nahet sie
sich, Already it gets closer,
... it would be really annoying to go through and delete one language in order to further process these lines of text.
One way I was thinking this could be done in NLTK was to split the text into tokens, have some way of knowing the provenance of each token based on a small corpus, and then ask NLTK to 'reconstitute' only the tokens of my choosing. Is this just a wild fantasy?
| 0
| 1
| 0
| 0
| 0
| 0
|
I am a graduate student in computer science at Indiana University, Bloomington. For one of my research projects, i am working on calculating pageranks for a directed graph which is very sparse and has a high percentage of deadlinks.
By deadlinks I mean nodes that have outdegree zero. Sometimes, in a graph with a lot of deadlinks, spider traps may occur. Anyways, the problem I am interested in is finding out pageranks in this scenario.
And I am using JUNG (Java Universal Graph Network) for calculating the pageranks.
When I use the normal procedure,
Graph<String, String> jungGraph = new DirectedSparseGraph<String, String>();
PageRank<String, String> pagerank = new PageRank<String,String>(jungGraph, 0.2);
pagerank.setMaxIterations(20);
pagerank.setTolerance(0.000001);
pagerank.evaluate();
I get more or less the same pagerank values for all the nodes, when i clearly know that shouldn't be the case. As some nodes in the graph have a large number of outgoing nodes and are strongly interconnected.
What is the suggested approach in this case. I know there is this class PageRankWithPriors. Should I first extract the network with no deadlinks, calculate pageranks for them, and then propagate their rank to the deadlinks until they converge.? In the latter case, all the nodes in the reduced network (outdegree != 0 ) will have their priors set, whereas the deadlinks wont.
Am I missing anything here?
| 0
| 0
| 0
| 1
| 0
| 0
|
What kind of problems on graphs is faster (in terms of big-O) to solve using incidence matrix data structures instead of more widespread adjacency matrices?
| 0
| 0
| 0
| 0
| 1
| 0
|
I have following equation:
f(N): N = ((1+lam)^3 )/ ((1-lam)*(1+lam^2));
I need to create a function that finds lam for specified N.
Right now I'm doing it using simple loop:
lam = 0.9999;
n = f(lam);
pow = 0;
delta = 0.1;
while(abs(N - n)) > 0.1 & pow < 10000)
lam = lam - 0.001;
n = f(lam)
pow = pow+1;
end
How can I solve it more accurate and without using loops?
| 0
| 0
| 0
| 0
| 1
| 0
|
I am a Computer Science student. I want to do an AI project for my 4th year with two other students. (It's a 5-year degree in my university so I can pursue the same project for two consecutive years if I want to). Our knowledge in AI is very basic at this moment since we'll be specializing in it these coming two years, so a very advanced idea will probably be hard to accomplish. We're not expected to research new untouched soils either, so the more resources the better.
I'm interested in ideas that can benefit people and not just applying algorithms and techniques. I want to do a masters after graduation, but I'm not sure in what field yet.
I'd love to do a medical application or a project that of some use to the handicapped.
Some projects that were already pursued at the university included a project to recognize breast cancer, and to teach sign language to the deaf.
I'm wondering:
1) what other ideas we can work on in those fields?
2) how much will my choice of graduation project affect my application for a masters degree?
3) Is a stocks price prediction expert system too advanced for us?
Thanks a lot.
| 0
| 1
| 0
| 0
| 0
| 0
|
Possible Duplicate:
PHP - How to split a paragraph into sentences.
I have a block of text that I would like to separate into sentences, what would be the best way of doing this? I thought of looking for '.','!','?' characters, but I realized there were some problems with this, such as when people use acronyms, or end a sentence with something like !?. What would be the best way to handle this? I figured there would be some regex that could handle this, but I'm open to a non-regex solution if that fits the problem better.
| 0
| 1
| 0
| 0
| 0
| 0
|
perc = 15/30;
//result=Math.round(perc*100)/100 //returns 28.45
$('#counter').text(perc);
$('#total').text(count);
returns back 0.5% which is suppose to be 50.00%... how do I fix this? :S
| 0
| 0
| 0
| 0
| 1
| 0
|
after profiling a lot I found out that this method takes up most of the % of calculation time. I don't really see a way to optimize, since it is a horrible function. (it is...)
Maybe someone can show me some nice idea or so?
public static double perceivedLoudness(double L_G, double L_ETQ, double a0) {
double t1 = 1d + 1 / 4d * Math.pow(10d, 0.1d * (L_G - a0 - L_ETQ));
double t2 = Math.pow(t1, 0.25);
return 0.064d * Math.pow(10, 0.025 * L_ETQ) * (t2 - 1);
}
Here is the improved version:
public static double perceivedLoudness(double L_G, double L_ETQ, double a0) {
double x = L_G - a0 - L_ETQ;
double t1 = 0.25 * Math.exp(0.230259 * x) + 1;
double t2 = Math.sqrt(Math.sqrt(t1));
return ltqFactors[(int)L_ETQ] * (t2 - 1);
}
The lookup for ltqFactors goes this way. ltqValues hold 20 points from the given ltq function, that approx should be sufficiant.
for( int i = 0; i < etqValues.length; ++i) {
ltqFactors[(int)etqValues[i]] = 0.064d * Math.exp(etqValues[i] * 0.05756462732485114210d);
}
Edit: After more test runs with more files, I come up to a ~100% speed up:
Old: 6,2% with 7000000 calls
New: 3,2% 8000000 calls.
Thank you so far!
Edit2: I don't know which answer to accept. :(
With some other improvements (mostly lookup tables) the processing time for 9000 sound files went down from 4:30min to 3:28min.
I will keep this question open to see if there are other ideas, but then accept one answer.
Edit: I'm kind of frustrated now. I use a JFace treeviewer to let the user browse the results, and it need more time to update than the calculations itself. :/
| 0
| 0
| 0
| 0
| 1
| 0
|
I can create a chart with a logarithmic scale on one axis, but I need to have a probability scale on the other axis as well.
Thanks in advance.
| 0
| 0
| 0
| 0
| 1
| 0
|
There is a group of simple formulas for calculating some values.
I need to implement this for the web interface (I make this in PHP).
To store formulas I am using simple format like this: "X1+X2+X3". When I need to make calculations, I call function preg_replace in the loop for replacing X1, X2 .. by real data (entered by user or saved earlier - it is not important)
Then I use function eval('$calculation_result ='. $trans_formula .';') where $trans_formula stores text of the formula with substituted data.
This mechanism looks like a primitive and I have a feeling that I'm trying to re-invent the wheel. Perhaps there are some ready algorithms, techniques, methods to accomplish this? Not necessary PHP code. I’ll appreciate even simple algorithm description.
| 0
| 0
| 0
| 0
| 1
| 0
|
I am trying to build question based on information available on about 10 variables- e.g. shape (square, circle, rectangle, paralellogram),length, width, circumference, area, diagonal length etc
e.g. if i want to set question to calculate area based on shape, length and width- the question gets created stating- calculate area of 'rectangle' given length='10' and width='5'. If i provide area and ask for width, the question autmatically forms as calculate area of 'rectangle' given length='10' and area='50'.
I am not too ambitious and am willing to be able to build this under constraints- any pointers around how I can achieve this? initial thoughts to have a question and answer fragment for each variable- but initial attempts creates very messy grammar
| 0
| 1
| 0
| 0
| 0
| 0
|
I don't understand what I am supposed to do in this exercise, I am beginning programming contest, if you can help me is very appreciated, I have seen formulas, but I don't understand what to do, I feel very stupid , and for everyone is easy :(
http://www.codeforces.com/contest/1/problem/A
| 0
| 0
| 0
| 0
| 1
| 0
|
I've used regex's in sed before and used a bit of awk, but am unsure of the exact syntax I need here...
I want to do something like:
sed -i 's/restartfreq\([\s]\)*\([0-9]\)*/restartfreq\1$((\2/2))/2/g' \
my_file.conf
where the second match is divided by 2 and then put back in the inline edit.
I've read though that sed can't do math.
Can I do this cleanly with sed or awk alone? Suggestions please.
Edit 1
I thought the meaning of my inquiry was straightforward enough, but I guess I might not have given a good enough sample of the data I want to modify. Here's and example of the line in my *.conf file I want to edit inline:
restartfreq 1250 ;# 2500steps = every 1.25 ps
I've posted a solution below. Both of the answers I received were with regards to printing text to the terminal, not editing a file inline. I try to avoid answering my own question, but in this case neither of the answers I received really did what I requested (edit the file, not just print the edited line) and they were substantially longer than my solution and/or required additional linux programs besides just awk or sed.
I do appreciate the help and feedback, though! :)
NOTE: As my usual disclaimer, this is not a homework question, I am a chemical engineering researcher.
| 0
| 0
| 0
| 0
| 1
| 0
|
I have a simple function that I'm using but for some reason the number doesn't calculate correctly as it would in a calculator. I think it has something to do with the numbers being too large, or something to do with 64 bit. Is there any way I can convert them so that they would work correctly?
$sSteamComID = 76561197990369545;
$steamBase = 76561197960265728;
function convertToSteamID($sSteamComID) {
$sServer = bcmod($sSteamComID, '2') == '0' ? '0' : '1';
$sCommID = bcsub($sSteamComID, $sServer);
$sCommID = bcsub($sCommID, $steamBase);
$sAuth = bcdiv($sCommID, '2');
echo "$sServer:$sAuth";
}
convertToSteamID($sSteamComID);
This function outputs 0:15051912 on a server when it should be printing 1:15051908
| 0
| 0
| 0
| 0
| 1
| 0
|
I want to create a fairly simple mathematical model that describes usage patterns and performance trade-offs in a system.
The system behaves as follows:
clients periodically issue multi-cast packets to a network of hosts
any host that receives the packet, responds with a unicast answer directly
the initiating host caches the responses for some given time period, then discards them
if the cache is full the next time a request is required, data is pulled from the cache not the network
packets are of a fixed size and always contain the same information
hosts are symmetic - any host can issue a request and respond to requests
I want to produce some simple mathematical models (and graphs) that describe the trade-offs available given some changes to the above system:
What happens where you vary the amount of time a host caches responses? How much data does this save? How many calls to the network do you avoid? (clearly depends on activity)
Suppose responses are also multi-cast, and any host that overhears another client's request can cache all the responses it hears - thereby saving itself potentially making a network request - how would this affect the overall state of the system?
Now, this one gets a bit more complicated - each request-response cycle alters the state of one other host in the network, so the more activity the quicker caches become invalid. How do I model the trade off between the number of hosts, the rate of activity, the "dirtyness" of the caches (assuming hosts listen in to other's responses) and how this changes with cache validity period? Not sure where to begin.
I don't really know what sort of mathematical model I need, or how I construct it. Clearly it's easier to just vary two parameters, but particularly with the last one, I've got maybe four variables changing that I want to explore.
Help and advice appreciated.
| 0
| 0
| 0
| 0
| 1
| 0
|
I am trying to generate random floats using nothing but bytes I get from /dev/urandom. Currently my best idea is to get the platform precision doing something like:
$maximumPrecision = strlen('' . 1/3) - 2;
and then construct a string of 0-9 in a loop the number of times $maximumPrecision tells us. For examle, if the precision is 12, I would generate 12 random numbers and concatenate them. I think it's an ugly idea.
Update: Does this make sense?
$bytes =getRandomBytes(7); // Just a function that returns random bytes.
$bytes[6] = $bytes[6] & chr(15); // Get rid off the other half
$bytes .= chr(0); // Add a null byte
$parts = unpack('V2', $bytes);
$number = $parts[1] + pow(2.0, 32) * $parts[2];
$number /= pow(2.0, 52);
| 0
| 0
| 0
| 0
| 1
| 0
|
I have a lost of sentences generated from http://www.ywing.net/graphicspaper.php, a random computer graphics paper title generator, some of example sentences sorted are as following:
Abstract Ambient Occlusion using Texture Mapping
Abstract Ambient Texture Mapping
Abstract Anisotropic Soft Shadows
Abstract Approximation
Abstract Approximation of Adaptive Soft Shadows using Culling
Abstract Approximation of Ambient Occlusion using Hardware-accelerated Clustering
Abstract Approximation of Distributed Surfaces using Estimation
Abstract Approximation of Geometry for Texture-mapped Ambient Occlusion
Abstract Approximation of Mipmaps for Opacity
Abstract Approximation of Occlusion Fields for Subsurface Scattering
Abstract Approximation of Soft Shadows using Reflective Texturing
Abstract Arbitrary Rendering
Abstract Attenuation and Displacement Mapping of Geometry
Abstract Attenuation of Ambient Occlusion using View-dependent Texture Mapping
Abstract Attenuation of Light Fields for Mipmaps
Abstract Attenuation of Non-linear Ambient Occlusion
Abstract Attenuation of Pre-computed Mipmaps using Re-meshing
- ...
I would like to try reverse engineering the grammar behind and learn how to do it in some sort of ways, like in common lisp way or NLTK way. Any ideas about that?
-- Drake
| 0
| 1
| 0
| 0
| 0
| 0
|
I'm looking for a java library for decision trees which accepts numeric attributes and classes/grades. Weka's J48 deals with discrete attributes but doesn't accept numeric ones.
Thanks
| 0
| 0
| 0
| 1
| 0
| 0
|
I have implemented an A* search algorithm for finding a shortest path between two states.
Algorithm uses a hash-map for storing best known distances for visited states. And one hash-map for storing child-parent relationships needed for reconstruction of the shortest path.
Here is the code. Implementation of the algorithm is generic (states only need to be "hashable" and "comparable") but in this particular case states are pairs (vectors) of ints [x y] and they represent one cell in a given heightmap (cost for jumping to neighboring cell depends on the difference in heights).
Question is whether it's possible to improve performance and how? Maybe by using some features from 1.2 or future versions, by changing logic of the algorithm implementation (e.g. using different way to store path) or changing state representation in this particular case?
Java implementation runs in an instant for this map and Clojure implementation takes about 40 seconds. Of course, there are some natural and obvious reasons for this: dynamic typing, persistent data structures, unnecessary (un)boxing of primitive types...
Using transients didn't make much difference.
| 0
| 1
| 0
| 0
| 0
| 0
|
I have been working on extracting the peak values from a graph (see previous question) which looks like this:
but I have noticed that for some of the xcorr graphs I have been working on the values do not turn out as expected and they normally turn out looking more like this:
and this:
Instead of trying to pick the peak values like the code was doing in the first figure, how would I go about trying to pick the values where the downward slope momentarily evens itself out (as shown in Figure 3)?
When I try and run the code in its current state on data like the ones shown in Figure 2 & 3, I do not get any useful data back in return.
I think I need an if statement or similar in the 'find extrema points' section but I'm not sure whether that is correct or not. My .M code for the function looks like this so far:
[inputname, pathname] = uigetfile('*.wav', 'Select WAV-file');
thumb1 = inputname; %# Get filename information
fprintf('
%s is being turned into a 30s thumbnail...
', thumb1);
fprintf('Please wait..!
');
%# load the signal
[y, fs, nb] = wavread(thumb1);
y = mean(y,2); %# stereo, take avrg of 2 channels
%# Calculate frame energy
fWidth = round(fs*1); %# 10ms
numFrames = floor(length(y)/fWidth);
energy = zeros(1,numFrames);
for f=1:numFrames
energy(f) = sum( y((f-1)*fWidth+1:f*fWidth).^2 );
end
%# smooth the signal (moving average with window size = 1% * length of data)
WINDOW_SIZE = round(length(energy) * 0.01); %# 200
XX = filtfilt(ones(1,WINDOW_SIZE)/WINDOW_SIZE, 1, energy);
%# auto-correlation
[r,lags] = xcorr(XX, 'biased');
%# find extrema points
dr = diff(r);
eIdx = find(dr(1:end-1) .* dr(2:end) <= 0) + 1;
[~,loc] = sort(r(eIdx), 'descend');
loc = loc(1:min(3,end)); %# take the highest 3 values
inf=lags( eIdx(loc) );
thumb=max(inf);
startrecord=round((thumb/1)*fs);
endrecord=round(((thumb+30)/1)*fs);
wavwrite(y(startrecord:endrecord), fs, nb, 'Temp1');
fprintf('The thumbnail of %s has been created.
', thumb1);
Sorry that it all looks so messy, but I wanted to get some visual examples in!
| 0
| 0
| 0
| 0
| 1
| 0
|
I have been tasked with figuring out a state space for a problem based on the area of a rectangle. It seems that I have made my state space far too large and need some feedback.
So far I have an area that has a value fo 600 for a y axis and 300 for an x axis. I determined the number of points to be
(600 x 300) ! or 180,000!
Therefore my robot would need to inspect this many potential spaces, before I apply an algorithm.
This number seems quite high and if that is the case it would make my problem unsolveable before I die especially if I implement the algorithm incorrectly. Any help would be greatly appreciated especially if my math is off in determining the number of points.
EDIT
I was under the impression to see how many pairs of points you would have to take the cartesian product of the total available points. Which in turn would be (600x300)! . If this is incorrect please let me know.
| 0
| 1
| 0
| 0
| 0
| 0
|
I'm not new to programming, but I am new to game programming. It was always my dream to create games, and since I'm 21 today, I think better start now than later.
In the past I had no problems with math, but I did have the constant feeling that I could solve the problems but not understand what was happening.
"Why am I doing this and what exactly does it solve?"
Where would I start if I want to start learning math for game programming?
Edit: Some people are asking me to say which kind of math I'm looking for, but truth be told I don't even know that. I'm a complete math newbie. I did a calculus class in Uni but like I said I just solved them but didn't really know why or how.
| 0
| 0
| 0
| 0
| 1
| 0
|
With StompChicken's corrections (I miscomputed one dot product, ugh!) the answer appears to be yes. I have since tested the same problem using a precomputed kernel with the same correct results. If you are using libsvm StompChickens clear, organized computations are a very nice check.
Original Question:
I am about to start using precomputed kernels in libSVM. I had noticed
Vlad's answer to a question and I thought it would be wise to confirm that libsvm gave correct answers. I started with non-precomputed kernels, just a simple linear kernel with 2 classes and three data points in 3 dimensional space. I used the data
1 1:3 2:1 3:0
2 1:3 2:3 3:1
1 1:7 3:9
The model file generated by a call to svm-train -s 0 - t 0 contains
svm_type c_svc
kernel_type linear
nr_class 2
total_sv 3
rho -1.53951
label 1 2
nr_sv 2 1
SV
0.4126650675419768 1:3 2:1 3:0
0.03174528241667363 1:7 3:9
-0.4444103499586504 1:3 2:3 3:1
However when I compute the solution by hand that is not what I get. Does anyone know whether libsvm suffers from errors or can anyone compare notes and see whether they get the same thing libsvm does?
The coefficients a1, a2, a3 returned by libsvm are should be the values that make
a1 + a2 + a3 - 5*a1*a1 + 12*a1*a2 - 21*a1*a3 - 19*a2*a2/2 + 21*a2*a3 - 65*a3*a3
as large as possible with the restrictions that
a1 + a3 = a2
and each of a1, a2, a3 is required to lie between 0 and 1 (the default value of C).
The above model file says the answer is
a1 = .412665...
a2 = .444410...
a3 = .031745...
But one just has to substitute a2 = a1 + a3 into the big formula above and confirm both partial derivatives are zero to see if this solution is correct (since none of a1,a2,a3 is 0 or 1) but they are not zero.
Am I doing something wrong, or is libsvm giving bad results? (I am hoping I am doing something wrong.)
| 0
| 0
| 0
| 1
| 0
| 0
|
I have this program that takes 3 scores out of a possible 200 each then is supposed to get the average and display the percentage. but when i input numbers i get 00.0 as an answer.
What could i be doing wrong?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int Score1;
int Score2;
int Score3;
Console.Write("Enter your score (out of 200 possible) on the first test: ");
Score1 = int.Parse(Console.ReadLine());
Console.Write("Enter your score (out of 200 possible) on the second test: ");
Score2 = int.Parse(Console.ReadLine());
Console.Write("Enter your score (out of 200 possible on the third test: ");
Score3 = int.Parse(Console.ReadLine());
Console.WriteLine("
");
float percent = (( Score1+ Score2+ Score3) / 600);
Console.WriteLine("Your percentage to date is: {0:00.0}", percent);
Console.ReadLine();
}
}
}
| 0
| 0
| 0
| 0
| 1
| 0
|
I need to know how to write a function to solve a simple linear equation like 2x +1 = 5. How would one do this? If anyone can show some code or point me to a site, it would be much appreciated.
| 0
| 0
| 0
| 0
| 1
| 0
|
Possible Duplicate:
Circle line collision detection
I'm trying to do collision testing between a finite line segment, and an arc segment. I have a collision test which does line segment vs. line segment, so I was going to approximate these arc segments with line segments and run my existing test.
The data I have defining the arc segment(s) are three points. Two of which are endpoints that lie on the circumference of a circle, and the third point is the center of that circle.
So far this is what I've got:
Let (a,b) be the center point of the circle, let 'r' be the radius of the circle, and (x1, y1), (x2, y2) be the endpoints of the arc segment which lies on the circumference of the circle.
The following parametric equations give the x, and y locations of an arc. 't' is the parametric variable.
x = a + r * cos(t)
y = b + r * sin(t)
To create the line segments from the arc, I wanted to walk the arc for some fixed ratio of 't' creating line segments along the way, until I've reached the end of the arc. To do this I figured I'd have to find the start and end angle. I'd start walking the arc from the start angle, and end at the end angle. Since I know the start and end points I figured I could use these equations to solve for these angles. The following are my equations for this:
t = arccos((x-a)/r)
or
t = acrcsin((y-b)/r)
The problem I'm having is that the range of values returned by these functions (http://en.wikipedia.org/wiki/Inverse_trigonometric_function) is limited, so there is a high probability that the angle I'm looking for will not be returned because these functions are multivalued: arcsin(0) = 0, but also arcsin(0) = π, arcsin(0) = 2π, etc
How do I get the exact angle(s) I'm looking for? Or, can you think of a better/different way of achieving my goal?
| 0
| 0
| 0
| 0
| 1
| 0
|
What would be the best regular expression for tokenizing an English text?
By an English token, I mean an atom consisting of maximum number of characters that can be meaningfully used for NLP purposes. An analogy is a "token" in any programming language (e.g. in C, '{', '[', 'hello', '&', etc. can be tokens). There is one restriction: Though English punctuation characters can be "meaningful", let's ignore them for the sake of simplicity when they do not appear in the middle of \w+. So, "Hello, world." yields 'hello' and 'world'; similarly, "You are good-looking." may yield either [you, are, good-looking] or [you, are, good, looking].
| 0
| 1
| 0
| 0
| 0
| 0
|
I have written an artifical neural network (ANN) implementation for myself (it was fun). I am thinking now about where can I use it.
What are the key areas in the real world, where ANN is being used?
| 0
| 1
| 0
| 0
| 0
| 0
|
We have a grid with red squares on it. Meaning we have an array of 3 squares (with angles == 90 deg) which as we know have same size, lying on the same plane and with same rotation relative to the plane they are lying on, and are not situated on same line on plane.
We have a projection of the space which contains the plane with squares.
We want to turn our plane projection with squares so that we would see it like it's facing us, in general we need a formula for turning each point of that original plane projection so that it would be facing us like on the image below.
What formulas can be used for solving such problem, how to solve it, has any one faced something like this before?
| 0
| 0
| 0
| 0
| 1
| 0
|
I am looking for recommended books (or other materials, like web pages) which demonstrate such examples -- structure of neural network (artificial) for given function.
I.e. what is the best (in sense, of being minimalistic, yet correct) network structure for function min with N arguments. Or for function abs. And so on.
The reason for my question (what books do you recommend?) is I would like to get proper "feeling" how to shape the network to get the desired effect without overkill having dense network which computes correctly, but very inefficiently.
| 0
| 1
| 0
| 0
| 0
| 0
|
I'm using Weka to perform classification on a set of labelled web pages, and measuring classifier performance with AUC. I have a separate six-level factor that is not used in classification, and I'd like to know how well classifiers perform on each level of the factor.
What techniques or measures should I use to test classifier performance on a subset of data?
| 0
| 0
| 0
| 1
| 0
| 0
|
I'm trying to create a simple STRIPS-based planner. I've completed the basic functionality to compute separate probabilistic plans that will reach a goal, but now I'm trying to determine how to aggregate these plans based on their initial action, to determine what the "overall" best action is at time t0.
Consider the following example. Utility, bounded between 0 and 1, represents how well the plan accomplishes the goal. CF, also bounded between 0 and 1, represents the certainty-factor, or the probability that performing the plan will result in the given utility.
Plan1: CF=0.01, Utility=0.7
Plan2: CF=0.002, Utility=0.9
Plan3: CF=0.03, Utility=0.03
If all three plans, which are mutually exclusive, start with the action A1, how should I aggregate them to determine the overall "fitness" for using action A1? My first thought is to sum the certainty-factors, and multiple that by the average of the utilities. Does that seem correct?
So my current result would look like:
fitness(A1) = (0.01 + 0.002 + 0.03) * (0.7 + 0.9 + 0.03)/3. = 0.02282
Or should I calculate the individual likely utilities, and average those?
fitness(A1) = (0.01*0.7 + 0.002*0.9 + 0.03*0.03)/3. = 0.00323
Is there a more theoretically sound way?
| 0
| 1
| 0
| 1
| 0
| 0
|
What happens when memdiff and/or totaldiff are negative? I was hoping for a negative memperc, but it doesn't seem like that's happening. Messing around in Python gives all sorts of confusing results when I plug in negative numbers.
local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
if mem then
if totaldiff == 0 then totaldiff = 0.001 end
memperc = (memdiff / totaldiff * 100)
local num = memperc
if num < 1 then num = 1 end
if num > 100 then num = 100 end
local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3]
return GetColorCode(format("%s (%.2f%%)", memshort(mem), memperc), r, g, b)
end
Edit: Oh come on, the question isn't a bad question. Maybe I should have been more clear on what I'm trying to do.
I'm taking two memory values, one overall and one specific to this addon. I'm creating a difference by doing thismem - lastmem. That's my difference. I have two of them, overall and addon specific. When Lua garbage collects, I get over 100% when I do memdiff / totaldiff * 100, when it should be negative. I don't know why.
Edit2:
Let me give some examples.
lastmem = 95
mem = 100.
lastaddonmem = 20
addonmem = 25.
totaldiff = mem - lastmem
addondiff = addonmem - lastaddonmem
perc = addondiff / totaldiff * 100
perc = 100
lastmem = 100
mem = 95.
lastaddonmem = 25
addonmem = 20.
totaldiff = mem - lastmem
addondiff = addonmem - lastaddonmem
perc = addondiff / totaldiff * 100
perc = 100
I know I'm going about this the wrong way. That's why I'm here.
Edit3: Why do you guys want to close this? I admit I'm dumb when it comes to math. Is it that people have that much intolerance for the mathematically challenged? I simply don't get math. Numbers confuse me like no other challenge of mine. I'm not uneducated. I have a learning disability. I don't see what the big deal is.
I ended up going with:
local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
if mem then
if totaldiff == 0 then totaldiff = 0.0001 end
local memperc
if memdiff < 0 then
memdiff = abs(memdiff)
totaldiff = abs(totaldiff)
memperc = memdiff / totaldiff * 100
memperc = memperc * -1
else
memperc = memdiff / totaldiff * 100
end
local num = floor(memperc)
if num < 1 then num = 1 end
if num > 100 then num = 100 end
local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3]
return GetColorCode(format("%s (%.2f%%)", memshort(mem), memperc), r, g, b)
end
| 0
| 0
| 0
| 0
| 1
| 0
|
If I have calculated an intersection point between a line segment and a circle, how can I tell whether or not this intersection point lies on a segment of the circle?
I have the equations to tell whether or not a line segment intersects with the circle, and I also have the intersection point on that circle, but what I need to know is whether or not this collision point on the circle lies within the bounds of a specific arg segment of that circle. I have the end points of the arc segment, the circle's center & radius, and the point of collision.
| 0
| 0
| 0
| 0
| 1
| 0
|
Those of you that are even moderately knowledgable of math will likely laugh, but I don't remember what much of the notation rules in math and I need assistance converting this into C code. Your help is greatly appreciated:
214
10,000 {(10,000 × [1+.0599/365] )} +300
answer = ────────────────────────────────────────────
214
.1+(1+(i/365))
| 0
| 0
| 0
| 0
| 1
| 0
|
Hey math geeks, I've got a problem that's been stumping me for a while now. It's for a personal project.
I've got three dots: red, green, and blue. They're positioned on a cardboard slip such that the red dot is in the lower left (0,0), the blue dot is in the lower right (1,0), and the green dot is in the upper left. Imagine stepping back and taking a picture of the card from an angle. If you were to find the center of each dot in the picture (let's say the units are pixels), how would you find the normal vector of the card's face in the picture (relative to the camera)?
Now a few things I've picked up about this problem:
The dots (in "real life") are always at a right angle. In the picture, they're only at a right angle if the camera has been rotated around the red dot along an "axis" (axis being the line created by the red and blue or red and green dots).
There are dots on only one side of the card. Thus, you know you'll never be looking at the back of it.
The distance of the card to the camera is irrelevant. If I knew the depth of each point, this would be a whole lot easier (just a simple cross product, no?).
The rotation of the card is irrelevant to what I'm looking for. In the tinkering that I've been doing to try to figure this one out, the rotation can be found with the help of the normal vector in the end. Whether or not the rotation is a part of (or product of) finding the normal vector is unknown to me.
Hope there's someone out there that's either done this or is a math genius. I've got two of my friends here helping me on it and we've--so far--been unsuccessful.
| 0
| 0
| 0
| 0
| 1
| 0
|
So we have such situation:
In this illustration, the first quadrilateral is shown on the Image Plane and the second quadrilateral is shown on the World Plane. [1]
In my particular case the Image Plane has 3 quadrilaterals - projections of real world squares, which, as we know, have same size, lying on the same plane, with same rotation relative to the plane they are lying on, and are not situated on same line on plane.
I wonder if we can get rotation angles of Image Plane to World Plane knowing stuff described?
In my case as input I have such data structures: original image (RGB pixels), objects (squares) with angles points in pixels (x,y) on Image Plane.
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm getting unexpected values for variable calculations:
$var1 = $var2 * (((1 + $var3)^$var4)^$var5);
I've verified that $var2 is 3, $var3 is 0.1, $var4 is 1, $var5 is 1.1 so,
$var1 = 3*(((1+0.1)^1)^1.1) = 3.3316 but in PHP, $var1 = 3
if I change $var4 to 2,
$var1 = 3*(((1+0.1)^1)^1.1) = 3.6999 but in PHP, $var1 = 6
Why is this? Any ideas? I've tried explicitly declaring all variables as floats.
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm doing this only for learning purposes. I've no intentions of reversing the methods of IMDB.
I asked myself I owned IMDB or similar website. How would I compute the movie rating?
All I can think of is Weighted Average(which is nothing but Arithmetic Mean)
For a movie data provided below computation would be
(38591*10 + 27994*9 + 32732*8 + 17864*7 + 7361*6 + 2965*5 + 1562*4 + 1073*3 + 891*2 + 3401*1) / 134434 = 8.17055953
My rating 8.17055953 doesn't match with IMDBs rating (=weighted average). So my conclusion is I'm missing something here or my score is not an ideal score. I'm might be missing lot of things.
Whats wrong with my score? Why is it not ideal?
If you had to compute. How would you have done it?
| 0
| 0
| 0
| 0
| 1
| 0
|
I have a list of double values that I don't know the range of and I want to find the maximum value. However, the Math.max function is giving a curious result for this sample code:
double a = -100.0;
double maxA = Double.MIN_VALUE;
maxA = Math.max(maxA, a);
System.out.println(maxA);
And the output is:
4.9E-324
So for some reason, Double.MIN_VALUE is being considered the max when compared to -100.0.
Why?
| 0
| 0
| 0
| 0
| 1
| 0
|
I have this grammar and need to modify it to allow parenthesis like: (-1) and -(1*5) possibly 1+(2*5) as well as unary the unary minus sign.
Does anyone have any suggestions of how to do so?
<expr> ::= <term> | <expr> <op1> <term>
<term> ::= <darg> |<term> <op2> <darg>
<darg> ::= <digit> | <darg> <digit>
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<op1> ::= + | -
<op2> ::= * | /
It seems like it would be something like this:
<expr> ::= <term> | <expr> <op1> <term>
<term> ::= <unary> |<term> <op2> <unary>
<unary> ::= <darg> | -<darg> | -<unary><darg>
<darg> ::= <digit> | <darg> <digit> | <paren>
<paren> ::= (<expr>)
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<op1> ::= + | -
<op2> ::= * | /
| 0
| 0
| 0
| 0
| 1
| 0
|
If I have 2 database records and 25 records per page, then the following code:
System.out.println("page count: " + (double)2/25);
results in this output:
page count: 0.08
But because I am using this figure for pagination, I need the next highest integer, in this case: 1.
Both Math.ceil and Math.abs produce the result 0 or 0.0.
How do I end up with a page number integer?
| 0
| 0
| 0
| 0
| 1
| 0
|
I've read the papers linked to in this question. I half get it. Can someone help me figure out how to implement it?
I assume that features are generated by some heuristic. Using a POS-tagger as an example; Maybe looking at training data shows that 'bird' is tagged with NOUN in all cases, so feature f1(z_(n-1),z_n,X,n) is generated as
(if x_n = 'bird' and z_n = NOUN then 1 else 0)
Where X is the input vector and Z is the output vector. During training for weights, we find that this f1 is never violated, so corresponding weight \1 (\ for lambda) would end up positive and relatively large after training. Both guessing features and training seem challenging implement, but otherwise straightforward.
I'm lost on how one applies the model to untagged data. Initialize the output vector with some arbitrary labels, and then change labels where they increase the sum over all the \ * f?
Any help on this would be greatly appreciated.
| 0
| 0
| 0
| 1
| 0
| 0
|
How can I define in numpy a matrix that uses operations modulo 2?
For example:
0 0 1 0 1 0
1 1 + 0 1 = 1 0
Thanks!
| 0
| 0
| 0
| 0
| 1
| 0
|
edit As someone has pointed out, what I'm looking for is actually the point minimizing total geodesic distance between all other points
My map is topographically similar to the ones in Pac Man and Asteroids. Going past the top will warp you to the bottom, and going past the left will warp you to the right.
Say I have two points (of the same mass) on the map and I wanted to find their center of mass. I could use the classical definition, which basically is the midpoint.
However, let's say the two points are on opposite ends of the mass. There is another center of mass, so to speak, formed by wrapping "around". Basically, it is the point equidistant to both other points, but linked by "wrapping around" the edge.
Example
b . O . . a . . O .
Two points O. Their "classical" midpoint/center of mass is the point marked a. However, another midpoint is also at b (b is equidistant to both points, by wrapping around).
In my situation, I want to pick the one that has lower average distance between the two points. In this case, a has an average distance between the two points of three steps. b has an average distance of two steps. So I would pick b.
One way to solve for the two-point situation is to simply test both the classical midpoint and the shortest wrapped-around midpoint, and use the one that has a shorter average distance.
However! This does not easily generalize to 3 points, or 4, or 5, or n points.
Is there a formula or algorithm that I could use to find this?
(Assume that all points will always be of equal mass. I only use "center of mass" because it is the only term I knew to loosely describe what I was trying to do)
If my explanation is unclear, I will try to explain it better.
| 0
| 0
| 0
| 0
| 1
| 0
|
This is just an out of curiosity question. Let's say you have a database table with 1m rows in it, and you want to often do queries like looking for either male or female, US or non-US, voter or non-voter etc, it's clearly very efficient to define a bitmap index for the table in which each bit represents one either-or condition.
However, to execute the query, you still have to scan through (probably) all of the index doing a bitand to select matching rows.
My question is is there some kind of bitmap-optimized storage such that the bit 'channels' are pre-created in the hardware? I'm envisaging something similar to knitting needles lifting punched cards out of an old library catalog system. In other words, rather than going row by row through memory locations, the chip can just pull out the matching rows electronically because there are hardware connections for each bit channel? I've a feeling the brain must work something like this. If I think of 'all blue objects', and then restrict that to 'all long blue objects' and then 'all long blue heavy objects', my brain does it effortlessly and I'm sure it's not scanning through all the objects I know about every time. It seems like perhaps there is some neurons that provide pathways for different dimensions for quick retrieval. I'm just wondering if there's anything like this in the hardware world?
Thanks!
| 0
| 1
| 0
| 0
| 0
| 0
|
Possible Duplicate:
Easy interview question got harder: given numbers 1..100, find the missing number(s)
Hi guys, I wasn't sure where to ask this but since this is an algorithmic question here it goes. I've come face to face with a math problem and can't seem to get over it for the last couple of days. It goes like this:
You are given an adding machine that
sums a set of N+1 digits consisting of
positive integers 1 to N as it's given
the numbers (e.g. the machine is given
3 as the first number and outputs 3.
It's then given 6 as the second number
and outputs 9. It's given 11 as the
third number and outputs 20. Etcetera
until it has processed N+1 numbers).
One (and only one) of the digits is
repeated. How do you determine which
number is repeated?
It seems like a trick question and I'd be really annoyed if it is just that a question to which the answer is 'not possible' - any ideas here?
| 0
| 0
| 0
| 0
| 1
| 0
|
I am wondering whether anyone knows a easy way to convert a latex math formula to a big jpeg file?
Here is the latex math formula:
\[
\lim_{u\rightarrow 0_+} \int_0^u \ud s \int_{-\infty}^\infty
\frac{f(u-s,x-y)}{\sqrt{2\pi
s}} \exp\left\{-\frac{y^2}{2s}\right\} \ud y
\]
Thanks!
| 0
| 0
| 0
| 0
| 1
| 0
|
How to I write a function that approximates a double in the following manner, returning an int:
function (2.3) -> 2
function (2.7) -> 3
function (-1.2) -> -1
function (-1.7) -> -2
| 0
| 0
| 0
| 0
| 1
| 0
|
My math knowledge has never been very broad, so this maybe a simple question but I'm not really sure.
Basically I'm using the curveTo function to draw some lines for flight paths, what I'm not sure how to do is dynamically finding the curve points, so for example if you look at the ryan air site: http://www.ryanair.com/en/cheap-flight-destinations all the lines are curved nicely.
current_line.graphics.curveTo(curveX, curveY, map.mouseX, map.mouseY);
I need to find the curveX and curveY
If you need anymore information, leave a comment and I'll answer any questions you have.
Thanks in advance
Will
| 0
| 0
| 0
| 0
| 1
| 0
|
Need advice:
I am implementing ID3 algorithm in Machine Learning. I am using dictionary to read the training file and store into. But as I am going forward I am understanding that in dictionary v dont have fixed places for each key,value pair as in list or array. Now I might have problem in getting the position of the final attribute and passing it dynamically to other functions. Should i change to some other data structure?
| 0
| 0
| 0
| 1
| 0
| 0
|
I'm trying to use topic modeling with Mallet but have a question.
How do I know when do I need to rebuild the model? For instance I have this amount of documents I crawled from the web, using topic modeling provided by Mallet I might be able to create the models and infer documents with it. But overtime, with new data that I crawled, new subjects may appear. In that case, how do I know whether I should rebuild the model from start till current?
I was thinking of doing so for documents I crawled each month. Can someone please advise?
So, is topic modeling more suitable for text under a fixed amount of topics (the input parameter k, no. of topics). If not, how do I really determine what number to use?
| 0
| 1
| 0
| 0
| 0
| 0
|
Given n points on the outline of the unit circle, I want to calculate the closest 2 points.
The points are not ordered, and I need to do it in O(n) (so I cannot sort them clockwise...)
I once knew the solution for this, but forgot it... the solution includes hashing, and splitting the circle to n or more slices.
If you found an algorithm to calculate only the distance, and not the specific points, it will be good enough..
| 0
| 0
| 0
| 0
| 1
| 0
|
Hey everyone, could anyone help me out with doing the Dollars in this function. It does the change just fine but it does all of the amount back in change and i want to big bills ($1,$5,$10, & $20)'s in dollars and the change in Q/D/N/P's.
Dim Quarters As Integer
Dim Dimes As Integer
Dim Nickels As Integer
Dim Pennies As Integer
Sub GetChange(ByVal Amount As Currency, ByRef Quarters As Integer, ByRef Dimes As Integer, ByRef Nickels As Integer, ByRef Pennies As Integer)
Dim Cents As Integer
Cents = Amount * 100
Quarters = Cents \ 25
Cents = Cents Mod 25
Dimes = Cents \ 10
Cents = Cents Mod 10
Nickels = Cents \ 5
Pennies = Cents Mod 5
End Sub
Call GetChange(5.56, Quarters, Dimes, Nickels, Pennies)
Any help would be awesome! :o)
Update, solved
Private Sub theUSChange(Amount)
Dim USCurrency(9) As Currency
Dim USCurrencyNames(9) As Currency
Dim Amount As Currency
Dim Result As Currency
Dim I As Integer
USCurrencyNames(0) = " Pennies: "
USCurrency(0) = 0.01
USCurrencyNames(1) = " Dimes: "
USCurrency(1) = 0.05
USCurrencyNames(2) = " Nickles: "
USCurrency(2) = 0.1
USCurrencyNames(3) = "Quarters: "
USCurrency(3) = 0.25
USCurrencyNames(4) = " $1: "
USCurrency(4) = 1
USCurrencyNames(5) = " $5: "
USCurrency(5) = 5
USCurrencyNames(6) = " $10: "
USCurrency(6) = 10
USCurrencyNames(7) = " $20: "
USCurrency(7) = 20
USCurrencyNames(8) = " $50: "
USCurrency(8) = 50
USCurrencyNames(9) = " $100: "
USCurrency(9) = 100
For I = UBound(USCurrency) To LBound(USCurrency) Step -1
Do While Amount >= USCurrency(I)
Amount = Amount - USCurrency(I)
Result = Result + 1
Loop
Debug.Print(USCurrencyNames(I) & Result)
Result = 0
Next
End Sub
call theUSChange(5.77)
OUTPUT:
$100: 0
$50: 0
$20: 0
$10: 0
$5: 1
$1: 0
Quarters: 3
Nickles: 0
Dimes: 0
Pennies: 2
David
| 0
| 0
| 0
| 0
| 1
| 0
|
Is there an efficient algorithm for finding all sequences of k non-negative integers that sum to n, while avoiding rotations (completely, if possible)? The order matters, but rotations are redundant for the problem I'm working on.
For example, with k = 3 and n = 3, I would want to get a list like the following:
(3, 0, 0), (2, 1, 0), (2, 0, 1), (1, 1, 1).
The tuple (0, 3, 0) should not be on the list, since it is a rotation of (3, 0, 0). However, (0, 3, 0) could be in the list instead of (3, 0, 0). Note that both (2, 1, 0) and (2, 0, 1) are on the list -- I do not want to avoid all permutations of a tuple, just rotations. Additionally, 0 is a valid entry -- I am not looking for partitions of n.
My current procedure is to loop from over 1 <= i <= n, set the first entry equal to i, and then recursively solve the problem for n' = n - i and k' = k - 1. I get some speed-up by mandating that no entry is strictly greater than the first, but this approach still generate a lot of rotations -- for example, given n = 4 and k = 3, both (2,2,0) and (2,0,2) are in the output list.
Edit: Added clarifications in bold. I apologize for not making these issues as clear as I should have in the original post.
| 0
| 0
| 0
| 0
| 1
| 0
|
I have three tables:
Charges
Payments
Adjustments
Each has a value, called Amount. There are no allocations done on this data, we are assuming the oldest Payments are paying the oldest Charges or Adjustments. Each Amount could be +ve or -ve.
I need to produce a report which shows the age of the debt, based on the current balance being in debt, where the balance is the sum of each Amount in all tables. However, the age of the debt must be the Age of the current debt. If an account was in debit in October, but was zeroed in November and then in Debit in February, the Age of the Debt would be February. In need to provide a 30, 60, 90 day breakdown of each account whose balance is outstanding.
Sorry if this isn't clear, but if you've done it before you'll know what I mean. Any pointers?
| 0
| 0
| 0
| 0
| 1
| 0
|
I made this graph in wolfram alpha by accident:
Can you write code to produce a larger version of this pattern?
Can you make similar looking patterns?
Readable code in any language is good, but something that can be run in a browser would be best (i.e. JavaScript / Canvas). If you write code in other languages, please include a screenshot.
Notes:
The input formula for the above image is: arg(sin(x+iy)) = sin^(-1)((sqrt(2) cos(x) sinh(y))/sqrt(cosh(2 y)-cos(2 x))) (link)
You don't have to use to use the above formula. Anything which produces a similar result would be cool. But "reverse engineering" Wolfram Alpha would be best
The two sides of the equation are equal (I think), So WA should have probably only returned 'true' instead of the graph
The pattern is probably the result of rounding errors.
I don't know if the pattern was generated by iterating over every pixel or if it's vector based (points and lines). My guess is with vector.
I don't know what causes this type of pattern ('Rounding errors' is the best guess.)
IEEE floating point standard does not say how sin or cos, etc should work, so trig functions vary between platforms and architectures.
No brownian motion plots please
Finally, here's another example which might help in your mission: (link)
| 0
| 0
| 0
| 0
| 1
| 0
|
As (hopefully) most of you know, floating point arithmetic is different from real number arithmetic. It's for starters imprecise. Many numbers, especially decimals (0.1, 0.3) cannot be represented, leading to problems like this. A more thorough list can be found here.
Are there any general purpose languages that have built-in support for something closer to real number arithmetic? If not, what are good libraries that support this?
EDIT: Arbitrary precision decimal
datatypes are not what I am looking
for. I want to be able to represent
numbers like 1/3, sqrt(3), or 1 + 2i as well.
| 0
| 0
| 0
| 0
| 1
| 0
|
We have a situation we want to do a sort of weighted average of two values w1 & w2, based on how far two other values v1 & v2 are away from zero... for example:
If v1 is zero, it doesn't get weighted at all so we return w2
If v2 is zero, it doesn't get weighted at all so we return w1
If both values are equally far from zero, we do a mean average and return (w1 + w2 )/2
I've inherited code like:
float calcWeightedAverage(v1,v2,w1,w2)
{
v1=fabs(v1);
v2=fabs(v2);
return (v1/(v1+v2))*w1 + (v2/(v1+v2)*w2);
}
For a bit of background, v1 & v2 represent how far two different knobs are turned, the weighting of their individual resultant effects only depends how much they are turned, not in which direction.
Clearly, this has a problem when v1==v2==0, since we end up with return (0/0)*w1 + (0/0)*w2 and you can't do 0/0. Putting a special test in for v1==v2==0 sounds horrible mathematically, even if it wasn't bad practice with floating-point numbers.
So I wondered if
there was a standard library function to handle this
there's a neater mathematical representation
| 0
| 0
| 0
| 0
| 1
| 0
|
Possible Duplicate:
Working with large numbers in PHP.
I run a completely useless Facebook app. I'm having a problem with PHP's support for integers. Basically, users give themselves ridiculous numbers of points. The current "king" has 102,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,002,557,529,927 points.
PHP does not seem to play well with large integers. When someone tries to add more than a certain amount of points it will fail because PHP treats those numbers as infinite.
Is there some math library for working with ridiculously large numbers? Should I treat the numbers as strings and write my own?
We're talking numbers which are 2^20 digits in length or longer. They don't need to be accurate (any errors are chalked up to the low quality of the app in general) nor does it need to be high performance. I just need something which allows much longer numbers.
(For those of you who are curious, we store our numbers in the cloud, so storage cost isn't a huge issue.)
| 0
| 0
| 0
| 0
| 1
| 0
|
Similar in how one would count from 0 to F in Hex, I have an array of numbers and letters I want to "count" from... and when I hit the max value, I want to start all over again in the "tens" column.
I need this to increase storage efficiency in Azure Table, and to keep my PrimaryKeys tiny (so I can use them in a tinyURL). First consider that only these characters are permitted as a propertyName, as documented here. In the array below, each character is positioned according to how Azure will sort it.
public static string[] AzureChars = new string[]
{
"0","1","2","3","4","5","6","7","8","9","A",
"B","C","D","E","F","G","H","I",
"J","K","L","M","N","O","P","Q",
"R","S","T","U","V","W","X","Y",
"Z","a","b","c","d","e","f","g",
"h","i","j","k","l","m","n","o",
"p","q","r","s","t","u","v","w",
"x","y","z"
};
My goal is to use 2 string/ASCII characters to count from the string "00" to lowercase "zz".
What is the best way to approach this concept using C#?
-- Is an array the correct object to use?
-- How will I associate a given character (uppercase 'Y') with it's position in the Array?
I'm just experimenting with this idea. At first brush it seems like a good one, but I haven't seen anyone consider doing things this way. What do you think?
| 0
| 0
| 0
| 0
| 1
| 0
|
What would be the best definition of an English word?
What are the other cases of an English word than just \w+?
Some may include \w+-\w+ or \w+'\w+; some may exclude cases like \b[0-9]+\b. But I haven't seen
any general consensus on those cases.
Do we have a formal defintion of such?
Can any of you clarify?
(Edit: broaden the question so it doesn't depend on regexp only.)
| 0
| 1
| 0
| 0
| 0
| 0
|
now i making some problem with JAVA, but don't remember how get lenght between to coordinate-system.
Ex.
point A (3,7)
Point B (7,59)
I want to know how count distance between point a and b. very thanks for your answers. :-)
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm well aware that a Double has only so many bits of precision, but we should still try to achieve high accuracy if possible. So I certainly do not expect to see this in the official .NET 4 system library.
// Summary:
// Represents the ratio of the circumference of a circle to its diameter,
// specified by the constant, π.
public const double PI = 3.14159;
Why only 6 digits? It would be easy and free to use an accurate value. I'm not doing scientific work in .NET, but I'm sure others do and they are in for a surprise when Pi is inaccurate. Same goes for E.
Edit: This tuned out to be about reflection of constants in Visual Studio. See followup question
| 0
| 0
| 0
| 0
| 1
| 0
|
I've been playing around with natural language parse trees and manipulating them in various ways. I've been using Stanford's Tregex and Tsurgeon tools but the code is a mess and doesn't fit in well with my mostly Python environment (those tools are Java and aren't ideal for tweaking). I'd like to have a toolset that would allow for easy hacking when I need more functionality. Are there any other tools that are well suited for doing pattern matching on trees and then manipulation of those matched branches?
For example, I'd like to take the following tree as input:
(ROOT
(S
(NP
(NP (NNP Bank))
(PP (IN of)
(NP (NNP America))))
(VP (VBD used)
(S
(VP (TO to)
(VP (VB be)
(VP (VBN called)
(NP
(NP (NNP Bank))
(PP (IN of)
(NP (NNP Italy)))))))))))
and (this is a simplified example):
Find any node with the label NP that has a first child with the label NP and some descendent named "Bank", and a second child with the label PP.
If that matches, then take all of the children of the PP node and move them to end of the matched NP's children.
For example, take this part of the tree:
(NP
(NP (NNP Bank))
(PP (IN of)
(NP (NNP America))))
and turn it into this:
(NP
(NP (NNP Bank) (IN of) (NP (NNP America))))
Since my input trees are S-expressions I've considered using Lisp (embedded into my Python program) but it's been so long that I've written anything significant in Lisp that I have no idea where to even start.
What would be a good way to describe the patterns? What would be a good way to describe the manipulations? What's a good way to think about this problem?
| 0
| 1
| 0
| 0
| 0
| 0
|
I posted something similar yesterday, but got nothing. I spent a few hours today problem-solving, but didn't progress any.
I'm using Processing (the language) and trying to implement a method that draws a line between two points. (I don't want to use the library's line() method.)
My lineCreate method works great for positive slopes, but fails with negative slopes. Can you help figure out why?
Here's the lineCreate() code:
void createLine(int x0, int y0, int x1, int y1){
//...
// Handle slanted lines...
double tempDX = x1 - x0;
double tempDY = y1 - y0; // Had to create dx and dy as doubles because typecasting dy/dx to a double data type wasn't working.
double m = (-tempDY / tempDX); // m = line slope. (Note - The dy value is negative
int deltaN = (2 * -dx); // deltaX is the amount to increment d after choosing the next pixel on the line.
int deltaNE = (2 * (-dy - dx)); // ...where X is the direction moved for that next pixel.
int deltaE = (2 * -dy); // deltaX variables are used below to plot line.
int deltaSE = (2 * (dy + dx));
int deltaS = (2 * dx);
int x = x0;
int y = y0;
int d = 0; // d = Amount d-value changes from pixel to pixel. Depends on slope.
int region = 0; // region = Variable to store slope region. Different regions require different formulas.
if(m > 1){ // if-statement: Initializes d, depending on the slope of the line.
d = -dy - (2 * dx); // If slope is 1-Infiniti. -> Use NE/N initialization for d.
region = 1;
}
else if(m == 1)
region = 2;
else if(m > 0 && m < 1){
d = (2 * -dy) - dx; // If slope is 0-1 -> Use NE/E initialization for d.
region = 3;
}
else if(m < 0 && m > -1){
d = (2 * dy) + dx; // If slope is 0-(-1) -> Use E/SE initliazation for d.
region = 4;
}
else if(m == -1)
region = 5;
else if(m < -1){
d = dy + (2 * dx); // If slope is (-1)-(-Infiniti) -> Use SE/S initialization for d.
region = 6;
}
while(x < x1){ // Until points are connected...
if(region == 1){ // If in region one...
if(d <= 0){ // and d<=0...
d += deltaNE; // Add deltaNE to d, and increment x and y.
x = x + 1;
y = y - 1;
}
else{
d += deltaN; // If d > 0 -> Add deltaN, and increment y.
y = y - 1;
}
}
else if(region == 2){
x = x + 1;
y = y - 1;
}
else if(region == 3){ // If region two...
if(d <= 0){
d += deltaE;
x = x + 1;
}
else{
d += deltaNE;
x = x + 1;
y = y - 1;
}
}
else if(region == 4){ // If region three...
if(d <= 0){
d += deltaSE;
x = x + 1;
y = y + 1;
}
else{
d += deltaE;
x = x + 1;
}
}
else if(region == 5){
x = x + 1;
y = y + 1;
}
else if(region == 6){ // If region four...
if(d <= 0){
d += deltaSE;
x = x + 1;
y = y + 1;
}
else{
d += deltaS;
y = y + 1;
}
}
point(x, y); // Paints new pixel on line going towards (x1,y1).
}
return;
}
| 0
| 0
| 0
| 0
| 1
| 0
|
I am attempting to generate a random numbers with a logarithmic distribution.
Where n=1 occurs half of the time, n=2 occurs a quarter of the time, n=3 occurs an eighth of the time, etc.
int maxN = 5;
int t = 1 << (maxN); // 2^maxN
int n = maxN -
((int) (Math.log((Math.random() * t))
/ Math.log(2))); // maxN - log2(1..maxN)
System.out.println("n=" + n);
Most of the time, I am getting the result I need, however once every so often, I get a value of n that is larger than maxN.
Why is this so? The way I see it, the max value of Math.random() is 1.0;
therefore the max value of (Math.random() * t)) is t;
therefore the max value of log2(t) is maxN, since t = 2^maxN;
Where has my logic gone off track?
Thanks
| 0
| 0
| 0
| 0
| 1
| 0
|
What I need is: plots creation, stuff for interpolation, stuff for counting such things as
and
where L(x) is an interpolation built from some data (points) generated from original known function f(x). meaning we know original function. we have a range (-a, a) - known. We need library to help us calculate data points in range. we need to calculate L(x) a polinom using that data in that range.
I need this library to be free and opensource
| 0
| 0
| 0
| 0
| 1
| 0
|
I’m using this equation to convert steps to estimated calories lost.
I now need to do the opposite and convert total calories to estimated steps.
This is the equation I’m using for steps to calories:
+(CGFloat) totalCalories:(NSUInteger)TotalStepsTaken weight:(CGFloat)PersonsWeight{
CGFloat TotalMinutesElapsed = (float)TotalStepsTaken / AverageStepsPerMinute; //Average Steps Per Minute is Equal to 100
CGFloat EstimatedCaloriesBurned = PersonsWeight * TotalMinutesElapsed * Walking3MphRate; //Walking3MphRate = 0.040;
return EstimatedCaloriesBurned;
}
It’s written in Objective-C, but I tried to make it as readable as possible.
All calculations are being done over a 1 hour period.
Thank you for you help.
| 0
| 0
| 0
| 0
| 1
| 0
|
I am trying to design a way to represent mathematical equations as Java Objects. This is what I've come up with so far:
Term
-Includes fields such as coefficient (which could be negative), exponent and variable (x, y, z, etc). Some fields may even qualify as their own terms alltogether, introducing recursion.
-Objects that extend Term would include things such as TrigTerm to represent trigonometric functions.
Equation
-This is a collection of Terms
-The toString() method of Equation would call the toString() method of all of its Terms and concatenate the results.
The overall idea is that I would be able to programmatically manipulate the equations (for example, a dirivative method that would return an equation that is the derivative of the equation it was called for, or an evaluate method that would evaluate an equation for a certain variable equaling a certain value).
What I have works fine for simple equations:
This is just two Terms: one with a variable "x" and an exponent "2" and another which is just a constant "3."
But not so much for more complex equations:
Yes, this is a terrible example but I'm just making a point.
So now for the question: what would be the best way to represent math equations as Java objects? Are there any libraries that already do this?
| 0
| 0
| 0
| 0
| 1
| 0
|
In ID3 implementation, at which point the recursion in Algorithm should stop.
| 0
| 0
| 0
| 1
| 0
| 0
|
I have the following function in my code:
int numberOverflow(int bit_count, int num, int twos) {
int min, max;
if (twos) {
min = (int) -pow(2, bit_count - 1); \\ line 145
max = (int) pow(2, bit_count - 1) - 1;
} else {
min = 0;
max = (int) pow(2, bit_count) - 1; \\ line 149
}
if (num > max && num < min) {
printf("The number %d is too large for it's destination (%d-bit)
", num, bit_count);
return 1;
} else {
return 0;
}
}
At compile time I get the following warning:
assemble.c: In function ‘numberOverflow’:
assemble.c:145: warning: incompatible implicit declaration of built-in function ‘pow’
assemble.c:149: warning: incompatible implicit declaration of built-in function ‘pow’
I'm at a loss for what is causing this... any ideas?
| 0
| 0
| 0
| 0
| 1
| 0
|
I am just starting to learn about the use of CRF++ toolkit.
I downloaded the linux version of CRF++ 0.54 ,
When i try to compile the example.cpp under sdk/ with the command
g++ -o example example.cpp
there comes the problem:
hpl@hpl-desktop:~/Documents/CRF/CRF++-0.54$ g++ -o a example.cpp
/tmp/ccmJQgGu.o: In function main':
example.cpp:(.text+0x12): undefined reference toCRFPP::createTagger(char const*)'
example.cpp:(.text+0x22): undefined reference to `CRFPP::getTaggerError()'
collect2: ld returned 1 exit status
I would appreciate any suggestions on how to make the program run.
David
| 0
| 1
| 0
| 0
| 0
| 0
|
Does anyone know a good one? I'm looking for multiplication of matrices, transpose, invert, converting from 4x4 to top left corner 3x3 etc.
| 0
| 0
| 0
| 0
| 1
| 0
|
Everyone,
here is a link to a small python app:
http://en.wikipedia.org/wiki/File:Beta-skeleton.svg
I think I've correctly converted it. (Source at bottom of post)
But, the Math.Acos always returns NaN. Is there a difference between the python version of acos and Math.Acos?
private Random rnd = new Random();
private double scale = 5;
private double radius = 10;
private double beta1 = 1.1;
private double beta2 = 0.9;
private double theta1;
private double theta2;
private Point[] points = new Point[10];
public MainWindow()
{
InitializeComponent();
for (int i = 0; i < 100; i++ )
{
points[i] = new Point((rnd.NextDouble() * scale),
(rnd.NextDouble() * scale));
}
theta1 = Math.Asin(1/beta1);
theta2 = Math.PI - Math.Asin(beta2);
}
private double Dot(Point p, Point q, Point r)
{
var pr = new Point();
var qr = new Point();
//(p[0]-r[0])
pr.X = p.X-r.X;
//(p[1]-r[1])
pr.Y = p.Y-r.Y;
//(q[0]-r[0])
qr.X = q.X-r.X;
//(q[1]-r[1])
qr.Y = q.Y-r.Y;
return (pr.X*qr.X) + (pr.Y*qr.Y);
}
private double Sharp(Point p,Point q)
{
double theta = 0;
foreach(var pnt in points)
{
if(pnt!=p && pnt!=q)
{
var dotpq = Dot(p, q, pnt);
double t = Math.Acos(dotpq);
double u = Math.Pow((dotpq * dotpq), 0.5);
var tempVal = t/u;
theta = Math.Max(theta, tempVal);
}
}
return theta;
}
private void DrawPoint(Point p)
{
var e = new Ellipse
{
Width = radius/2,
Height = radius/2,
Stroke = Brushes.Red,
Visibility = Visibility.Visible
};
Canvas.SetTop(e, p.Y + radius);
Canvas.SetLeft(e, p.X + radius);
MyCanvas.Children.Add(e);
}
private void DrawEdge1(Point p,Point q)
{
var l = new Line
{
X1 = p.X,
Y1 = p.Y,
X2 = q.X,
Y2 = q.Y,
Stroke = Brushes.Black,
Width = 1,
Visibility = Visibility.Visible
};
MyCanvas.Children.Add(l);
}
private void DrawEdge2(Point p,Point q)
{
var l = new Line
{
X1 = p.X,
Y1 = p.Y,
X2 = q.X,
Y2 = q.Y,
Stroke = Brushes.Blue,
Width = 1,
Visibility = Visibility.Visible
};
MyCanvas.Children.Add(l);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
foreach (var p in points)
{
foreach (var q in points)
{
var theta = Sharp(p, q);
if(theta < theta1) DrawEdge1(p, q);
else if(theta < theta2) DrawEdge2(p, q);
}
}
}
| 0
| 0
| 0
| 0
| 1
| 0
|
[This was initially on matrices, but I guess it applies to any variable generically]
Say we have Var1 * Var2 * Var3 * Var4.
One of them sporadically changes, which one of them is random.
Is it possible to minimize multiplications?
If I do
In case Var1 changes: newVar1 * savedVar2Var3Var4
I noticed that then I need to recalculate savedVar2Var3Var4 each time Var2, Var3, Var4 change.
Would that re-calculation of 'saved combinations' defy the purpose?
| 0
| 0
| 0
| 0
| 1
| 0
|
Given time-series data, I want to find the best fitting logarithmic curve. What are good libraries for doing this in either Python or SQL?
Edit: Specifically, what I'm looking for is a library that can fit data resembling a sigmoid function, with upper and lower horizontal asymptotes.
| 0
| 0
| 0
| 1
| 1
| 0
|
It seems that I cant use system.math class within the windows phone projects. I can't even add the mscorelib.dll manually (windows phone dlls are different than windows dlls)
Is there any way to use System.Math class within the windows phone SDK projects?
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm not the best in Maths, but for what I am doing now I need to calculate the angle of the vector which is shown as arrow in the picture below:
I have a point A and a point B in a 2D plane. I need to calculate the following:
The angle in which the arrow must be rotated in order to point to B
| 0
| 0
| 0
| 0
| 1
| 0
|
I have a bit of javascript that dynamically multiplies what users are typing in a text field (by the base var), and displays it in a span. Now I'm just trying to figure out how to get the decimal places of the result to float to 2 places, i.e. 10.00 instead of 10
I found the toFixed function, but can't seem to use it properly... I'd appreciate any help. Thanks
<input id="quantity">
<span id="result"></span>
<script>
window.onload = function() {
var base = 3;
document.getElementById('quantity').onkeyup = function() {
if(this.value.length == 0) {
document.getElementById('result').innerHTML = '';
return;
}
var number = parseInt(this.value);
if(isNaN(number)) return;
document.getElementById('result').innerHTML = number * base;
};
document.getElementById('quantity').onkeyup();
};
| 0
| 0
| 0
| 0
| 1
| 0
|
I have a set of points. This set of points do define a (non convex) polygon but its not ordered.
Since it's not ordered I cannot just draw from point to point to draw its border. How can I sort it in a way I can walk through this point list and draw a polygon?
My first idea was to use a convex hull but my polygons are, most of the time, concave.
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm using HTML 5 to render elliptic pie charts per section; using a path that starts from the centre, out to the edge, across it's arc and back to the centre which is then filled.
If they were perfectly circular I could use the arc or arcTo path functions, but because they're elliptical the outer curves will always have a variable radius.
It's these outer curves that I'm trying to figure out how to draw. I can't hack the maths enough to know if quadratic or bezier curves are the answer but they could be.
Anyway, the only way I've found to do it is to render lines for every 0.1 degrees around the edge, which does sine and cos calculations per point and is horribly inefficient. It looks like this (javascript):
while (arcAng <= curAng + dTheta) {
this.parent2d.lineTo(this.left + (this.width / 2) + (this.width / 2) * Math.cos(arcAng * (Math.PI / 180)),
this.top + (this.height / 2) + (this.height / 2) * Math.sin(arcAng * (Math.PI / 180)));
arcAng += 0.1;
}
Can anyone tell me the most efficient way to do this?
| 0
| 0
| 0
| 0
| 1
| 0
|
Alright, so warsow has some pretty excellent hud code with the exception that the math logic is a bit screwy.
Input:
a*b + c*d
Interpreted as:
((d*c) + b) * a
As you can see, the game does a series of operations in reverse order without regard to order of operations. Parentheses do not work in the hud code. It must be a linear series of operations to come up with the end result. Is this possible?
I understand that it would be better to implement proper math into the hud code, but this is way more fun imo.
| 0
| 0
| 0
| 0
| 1
| 0
|
I would like to port a chess AI to iPhone, but I can't figure out how to do it. Apparently iPhone doesn't support multi threading so you can't just seperately compile the AI, but have to somehow merge it into the code.
I have a GPL copy of a implementation of the sjeng engine, but I can't figure out how they did it because it's written in c and c++ and all I know is apple objc.
Does anyone have any recommendations on how to do this? I need to make a wrapper of some kind for what is a standalone program.
file with code which I will leave up for as long as I can.
| 0
| 1
| 0
| 0
| 0
| 0
|
Is there something similar to Princeton's WordNet in Spanish?
I need to find synonyms in Spanish.
| 0
| 1
| 0
| 0
| 0
| 0
|
I've got this function, which I modified from material in chapter 1 of the online NLTK book. It's been very useful to me but, despite reading the chapter on Unicode, I feel just as lost as before.
def openbookreturnvocab(book):
fileopen = open(book)
rawness = fileopen.read()
tokens = nltk.wordpunct_tokenize(rawness)
nltktext = nltk.Text(tokens)
nltkwords = [w.lower() for w in nltktext]
nltkvocab = sorted(set(nltkwords))
return nltkvocab
When I tried it the other day on Also Sprach Zarathustra, it clobbered words with an umlat over the o's and u's. I'm sure some of you will know why that happened. I'm also sure that it's quite easy to fix. I know that it just has to do with calling a function that re-encodes the tokens into unicode strings. If so, that it seems to me it might not happen inside that function definition at all, but here, where I prepare to write to file:
def jotindex(jotted, filename, readmethod):
filemydata = open(filename, readmethod)
jottedf = '
'.join(jotted)
filemydata.write(jottedf)
filemydata.close()
return 0
I heard that what I had to do was encode the string into unicode after reading it from the file. I tried amending the function like so:
def openbookreturnvocab(book):
fileopen = open(book)
rawness = fileopen.read()
unirawness = rawness.decode('utf-8')
tokens = nltk.wordpunct_tokenize(unirawness)
nltktext = nltk.Text(tokens)
nltkwords = [w.lower() for w in nltktext]
nltkvocab = sorted(set(nltkwords))
return nltkvocab
But that brought this error, when I used it on Hungarian. When I used it on German, I had no errors.
>>> import bookroutines
>>> elles1 = bookroutines.openbookreturnvocab("lk1-les1")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "bookroutines.py", line 9, in openbookreturnvocab
nltktext = nltk.Text(tokens)
File "/usr/lib/pymodules/python2.6/nltk/text.py", line 285, in __init__
self.name = " ".join(map(str, tokens[:8])) + "..."
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 4: ordinal not in range(128)
I fixed the function that files the data like so:
def jotindex(jotted, filename, readmethod):
filemydata = open(filename, readmethod)
jottedf = u'
'.join(jotted)
filemydata.write(jottedf)
filemydata.close()
return 0
However, that brought this error, when I tried to file the German:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "bookroutines.py", line 23, in jotindex
filemydata.write(jottedf)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 414: ordinal not in range(128)
>>>
...which is what you get when you try to write the u'
'.join'ed data.
>>> jottedf = u'/n'.join(elles1)
>>> filemydata.write(jottedf)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 504: ordinal not in range(128)
| 0
| 1
| 0
| 0
| 0
| 0
|
I'm trying to come up with a proper algorithm to create a matrix which gets the quad to face the camer straight up but I'm having difficulty.
The quad I'm drawing is facing downwards, here's the code I have so far:
D3DXVECTOR3 pos;
pos = D3DXVECTOR3(-2.0f, 6.0f, 0.1f);
D3DXMATRIX transform;
D3DXMatrixTranslation(&transform, pos.x, pos.y, pos.z);
D3DXVECTOR3 axis = D3DXVECTOR3(0, -1, 0);
D3DXVECTOR3 quadtocam = pos - EmCameraManager::Get().GetPosition();
D3DXVec3Normalize(&quadtocam,&quadtocam);
D3DXVECTOR3 ortho;
D3DXVec3Cross(&ortho, &axis, &quadtocam);
float rotAngle = acos(D3DXVec3Dot(&axis,&quadtocam));
D3DXMATRIX rot;
D3DXMatrixRotationAxis(&rot,&ortho,rotAngle);
transform = rot*transform;
This works when it comes to making the quad face the camera however it doesn't stay up right when facing it from all angles.
In this screen shot: http://imgur.com/hFmzc.png On the left the quad is being viewed straight on (vector is 0,0,1), in the other its being viewed from an arbitrary angle.
Both times it's facing the camera, however when from an arbitrary angle its tilting along its local z axis. I'm not sure how to fix it and was wondering what the next step here would be?
| 0
| 0
| 0
| 0
| 1
| 0
|
I have an array of "lines" each defined by 2 points. I am working with only the line segments lying between those points. I need to search lines that could continue one another (relative to some angle) and lie on the same line (with some offset)
I mean I had something like 3 lines
I solved some mathematical problem (formulation of which is my question) and got understanding that there are lines that could be called relatively one line (with some angle K and offset J)
And of course by math formulation I meant some kind of math formula like
| 0
| 0
| 0
| 0
| 1
| 0
|
I have the following:
An image - a hand drawn map - of an area of roughly 600x400 meters. The image is drawn on top of Google Maps tiles.
The latitude/longitude (from Google Maps) of the corners of this image. Or put differently, I have the north and south latitude and the east and west longitude of the image.
A latitude/longitude coordinate from iPhone's CoreLocation.
How do I draw a point on this image (or nothing if it's out of bounds), representing the coordinate from CoreLocation?
Added bonus: draw an arrow on the edge of the map, pointing to the coordinate, if the coordinate is out of bounds of the image.
I would like to do this without using a library like proj, in order to not have to bundle a large library, and understand what I'm doing and why.
As you probably guessed by know, I'm writing this in Objective-C. Your answer doesn't have to be in Objective-C, though.
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm trying to make to make a script to help me with my maths
example equation: y=(4*(x*2)^(2x+4))+4*x^2
For this to work, I just need it to understand that only (x*2) needs to be put to the power of (2x+4), and then to sub that back into the original equation, which of course you can just eval() an answer.
I want to calculate the values of y, when I know an x value. This WOULD be relatively easy if it weren't for powers. I just can't get my head round how to do them.
I know you can use pow(), but I'm trying to make a script to work with any equation. So it sort of needs to understand the syntax.
Any suggestions how to go about this?
| 0
| 0
| 0
| 0
| 1
| 0
|
I have g++ 4.4.3 on Linux with Ubuntu Lucid Lynx, and I am getting a:
-nan
as a result. On Hardy Heron with g++ 4.3.1, I am getting all
nan
This is causing my text diff regression to fail, since I am using cout to print this numerical result.
What is the meaning of a signed nan, and is there a way to tell the compiler that an unsigned nan is sufficient?
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm trying to perform the following integral in Maple:
simplify(int(a*x^2*e^(-a*x^2), x = -infinity .. infinity))
But instead of returning an answer, Maple just returns back the integral statement itself:
int(a*x^2*e^(-a*x^2), x = -infinity .. infinity)
In the prettier form though (with the actual integral sign, etc). I've tried removing the "simplify()" but it doesn't make any difference.
Any idea why that is? It should return a value.
| 0
| 0
| 0
| 0
| 1
| 0
|
Do you know how to fix the following issue with math precision?
p RUBY_VERSION # => "1.9.1"
p 0.1%1 # => 0.1
p 1.1%1 # => 0.1
p 90.0%1 # => 0.0
p 90.1%1 # => 0.0999999999999943
p 900.1%1 # => 0.100000000000023
p RUBY_VERSION # => "1.9.2"
p 0.1%1 # => 0.1
p 1.1%1 # => 0.10000000000000009
p 90.0%1 # => 0.0
p 90.1%1 # => 0.09999999999999432
p 900.1%1 # => 0.10000000000002274
| 0
| 0
| 0
| 0
| 1
| 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.