text
stringlengths 0
27.6k
| python
int64 0
1
| DeepLearning or NLP
int64 0
1
| Other
int64 0
1
| Machine Learning
int64 0
1
| Mathematics
int64 0
1
| Trash
int64 0
1
|
|---|---|---|---|---|---|---|
I'm working in a language that can only do binary math on 16-bit numbers but I need to use binary math on 32-bit values so I have to make some of my own functions. For example, I implemented binary OR as:
_32bit_or(a,b){
var{
a1=round(a/(2**16));
a2=a%(2**16);
b1=round(b/(2**16));
b2=b%(2**16);
}
.=((a1|b1) * (2**16)) + (a2|b2);
}
Split the 32-bit value into two 16-bit portions, OR each portion, and recombine. Simple enough.
But I now need to implement shifting which isn't as easy because by breaking the numbers apart, shifting, and then recombining, I'm losing bits! What I tried was:
_32bit_rshift(a,b){
var{
a1=round(a/(2**16));
a2=a%(2**16);
}
. = ((a1>>b) * (2**16)) + (a2>>b)
}
But this of course doesn't work as I mentioned. Can anyone provide some input?
| 0
| 0
| 0
| 0
| 1
| 0
|
This is a long shot, but I thought I might try before starting the dirty work.
I've got a project to build an application which will, for a defined input stations (vertices) and lines (edges), that is, a real map of some public transportation, schematize a given map into a metro map. I've done some research on the problem and it's an NP-complete problem equivalent to the 3-SAT problem. I also have some theoretic ideas on how to generate such a map, but they aren't detailed enough.
What I'm looking for is any other existing solution of this problem, some sort of pseudo-code, some real code in (almost) any other programming language etc, anything that would reduce the time I need to spend working on the algorithm itself, which will in return give me more time to work on other aspects of the application.
If anyone has ever seen anything that can help me, I'd appreciate it very much.
| 0
| 0
| 0
| 0
| 1
| 0
|
I am animating an object along a spline path in OpenGL. I am using some code I found to generate the spline. Sadly, I don't yet understand the mechanics of it. I want my object to align to match the tangent of path so that it looks like its following the path.
Two questions.
How do I find a vector that is tangent to the path at a given point?
Secondly, given that vector and a vector pointing up, how do rotate the object to align?
Here is my spline code.
public Spline(Vector Path[])
{
ControlPoints = Path;
// Flatten out the control points array.
int len = ControlPoints.length;
float[] controlsX = new float[len];
float[] controlsY = new float[len];
float[] controlsZ = new float[len];
for (int i = 0; i < len; ++i)
{
controlsX[i] = ControlPoints[i].x;
controlsY[i] = ControlPoints[i].y;
controlsZ[i] = ControlPoints[i].z;
}
// Calculate the gamma values just once.
final int n = ControlPoints.length - 1;
float[] gamma = new float[n + 1];
gamma[0] = 1.0f / 2.0f;
for (int i = 1; i < n; ++i) gamma[i] = 1 / (4 - gamma[i - 1]);
gamma[n] = 1 / (2 - gamma[n - 1]);
// Calculate the cubic segments.
cubicX = calcNaturalCubic(n, controlsX, gamma);
cubicY = calcNaturalCubic(n, controlsY, gamma);
cubicZ = calcNaturalCubic(n, controlsZ, gamma);
}
private Cubic[] calcNaturalCubic(int n, float[] x, float[] gamma)
{
float[] delta = new float[n + 1];
delta[0] = 3 * (x[1] - x[0]) * gamma[0];
for (int i = 1; i < n; ++i)
{
delta[i] = (3 * (x[i + 1] - x[i - 1]) - delta[i - 1]) * gamma[i];
}
delta[n] = (3 * (x[n] - x[n - 1])-delta[n - 1]) * gamma[n];
float[] D = new float[n + 1];
D[n] = delta[n];
for (int i = n - 1; i >= 0; --i)
{
D[i] = delta[i] - gamma[i] * D[i + 1];
}
// Calculate the cubic segments.
Cubic[] C = new Cubic[n];
for (int i = 0; i < n; i++) {
final float a = x[i];
final float b = D[i];
final float c = 3 * (x[i + 1] - x[i]) - 2 * D[i] - D[i + 1];
final float d = 2 * (x[i] - x[i + 1]) + D[i] + D[i + 1];
C[i] = new Cubic(a, b, c, d);
}
return C;
}
final public Vector GetPoint(float Position)
{
if(Position >= 1) { return ControlPoints[ControlPoints.length - 1]; }
float position = Position * cubicX.length;
int splineIndex = (int)Math.floor(position);
float splinePosition = position - splineIndex;
return new Vector(cubicX[splineIndex].eval(splinePosition), cubicY[splineIndex].eval(splinePosition), cubicZ[splineIndex].eval(splinePosition));
}
| 0
| 0
| 0
| 0
| 1
| 0
|
I am trying to create a scatter chart on my web page with CSS and few dots images. I have created the design successfully, but now I can't figure out how a scatter chart actually works. Can anyone provide me any idea how I can arrange them? My chart width is 968 and height 432.
like this chart
http://chart.apis.google.com/chart?cht=s&chd=t:12,16,16,24,26,28,41,51,66,68,13,45,81|16,14,22,34,22,31,31,48,71,64,15,38,84&chs=250x100&chl=Hello|World
i cannot use this but i want to know how it works
Thanks for any help.
<?php
$w = 968; $h = 432;
$xmin = 0; $xmax = 968;
$ymin = 10; $ymax = 100;
$x = 10; $y = 10;
$xc = 20;
$yc = 20;
$r = (20)/ 2;
$xc = $w * (($x - $xmin)/($xmax - $xmin)) - $r . "<br>";
$yc = $h * (($ymax - $y)/($ymax - $ymin)) -$r;
$tr ='';
$data = array("120|90","345|456","45|66","45|45");
foreach($data as $value){
$new = explode("|",$value);
$tr .='<a href="#" style="top:'.$new[0].'px; left:'.$new[1].'px;" class="dot"></a>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#most_engaged_graph{
width:968px;
height:432px;
background-color:#CCCCCC;
}
a.dot {
height:20px;
width:20px;
position:absolute;
background-color:#0033FF;
}
</style>
</head>
<body>
<div id="most_engaged_graph">
<?=$tr?>
</div>
</body>
</html>
| 0
| 0
| 0
| 0
| 1
| 0
|
Is there any software available on Linux for Galois field calculus?
| 0
| 0
| 0
| 0
| 1
| 0
|
I want to make a first person 3d game but I can't set the camera formula right.
So I have a rotation: 0 to 359. Next the x,y coordinates, z remains the same.
Camera rotation : 0 - front, 90 - left, 180 - back, 270 - right but I can adapt it
What is the formula for the camera ?
Platform: Panda3d, python, opengl
Thank you
| 0
| 0
| 0
| 0
| 1
| 0
|
I have to implement the value iteration algorithm for finding the optimal policy for each state of an MDP using Bellman's equation.
The input file is some thing like below:
s1 0 (a1 s1 0.5) (a1 s2 0.5) (a2 s1 1.0)
s2 0 (a1 s2 1.0) (a2 s1 0.5) (a2 s3 0.5)
s3 10 (a1 s2 1.0) (a2 s3 0.5) (a2 s4 0.5)
where s1 is the state 0 is the reward associated with s1. Upon taking action a1, we stay in s1 with probability 0.5. Upon taking action a1, we go to s2 with probability 0.5.Upon taking action a2, we stay in s1 with probability 1.0.
And similarly the others.
After reading the input file, I have to store it in some data structure. Which would be the appropriate data structure to do so in PYTHON so that traversing through it is easy.
| 0
| 0
| 0
| 1
| 0
| 0
|
Could you suggest a fast, deterministic method that is usable in practice, for testing if a large number is prime or not?
Also, I would like to know how to use non-deterministic primality tests correctly. For example, if I'm using such a method, I can be sure that a number is not prime if the output is "no", but what about the other case, when the output is "probably"? Do I have to test for primality manually in this case?
Thanks in advance.
| 0
| 0
| 0
| 0
| 1
| 0
|
Am I missing something? from FIPS180-2, on page 25, it gives the values of u1, u2, g^u1 mod p, y^u2 mod p and v. i have calculated all the values except v. yet, when i do the math, my calculations refuse to be v = 0x8bac1ab66410435cb7181f95b16ab97c92b341c0. instead, i get v = 0xc5a54698ae8e5b94661134260594ff4e3f488e26, which is not equal to r, from before. im doing (pow(g, u1, p) * pow(y, u2, p)) % q to do the calculation, where pow is the builtin function, not the math module function
| 0
| 0
| 0
| 0
| 1
| 0
|
I would like to know how to find the rotation matrix for a set of features in a frame.
I will be more specific. I have 2 frames with 20 features, let's say frame 1 and frame 2. I could estimate the location of the features in both frames. For example let say a certain frame 1 feature at location (x, y) and I know exactly where it is so let's say (x',y').
My question is that the features are moved and probably rotated so I wanna know how to compute the rotation matrix, I know the rotation matrix for 2D:
But I don't know how to compute the angle, and how to do that? I tried a function in OpenCV which is cv2DRotationMatrix(); but the problem which as I mentioned above I don't know how to compute the angle for the rotation matrix and another problem which it gives 2*3 matrix, so it won't work out cause if I will take this 20*2 matrix, (20 is the number of features and 2 are the location in (x,y)) and multiply it by the matrix by 2*3 which is the results from the function then I will get 20*3 matrix which it doesn't seem to be realistic cause I'm working with 2D.
So what should I do? To be more specific again, show me how to compute the angle to use it in the matrix?
| 0
| 0
| 0
| 0
| 1
| 0
|
have a trouble understanding this expression:
(x + y - 1) / y * y
The operators precedence is as follows (as per my understanding and K&R2, 2.12 table 2.1):
1) evaluate what is in the parens: firstly (x+y), then (x+y) -1
2) '*' operator has higher priority then '/' so it's supposed to go first, bit it appears that (y * y) is evaluated and then the result of (x+y-1) is divided by the product (y*y). I don't quite get it.
3) I ever heard that normally rounding up iw written in this form:
(x + y - 1) / y * y
Is that correct? Thank you very much in advance!
| 0
| 0
| 0
| 0
| 1
| 0
|
Greetings.
I have a java method that I consider expensive, and I'm trying to replace some calls to it with a mathematical expression. Problem is, I suck at math. I mean really suck.
The following should explain the pattern that I'm trying to exploit.
f(x) -> y
f(x*2) -> f(x)+1
That is, whenever I double the value for x, the value for y will be 1 greater than for x/2.
Here are some example output:
f(5) -> 6
f(10) -> 7
f(20) -> 8
f(40) -> 9
f(80) -> 10
f(160) -> 11
f(320) -> 12
My current approach is brute force. I'm looping over the X and test how many times I can halve it before I reach 5, and finally I add 6. This works and is faster than the call to the original method. But I was looking for a more "elegant" or potentially cheaper solution.
Accepted answer goes to the one who manages to help me without pointing out how stupid I am :)
(the title probably sucks, because I don't know what I'm looking for)
| 0
| 0
| 0
| 0
| 1
| 0
|
I know that I can round a number like this
var number = 1.3;
Math.round(number);
and the result I'm given is 1.
But how can I round a number to the next highest whole number? So round 1.3 to 2 instead of 1?
| 0
| 0
| 0
| 0
| 1
| 0
|
I know there are some optimized algorithms around for all kind of matrix decompositions (QR decomposition, SVD,...), multiplications and the likes. Yet, I couldn't find a good overview. For C++, there is quite some useful information in this question, but I'm looking for those things in C.
| 0
| 0
| 0
| 0
| 1
| 0
|
I.e., I get a list of words and I want to construct a simple regular expression from that which matches at least all of the words (but maybe more).
I want to have an algorithm for that. I.e. input of that algorithm is a list of words and output is a regular expression. Obviously, there will be some restrictions. Like either the regular expression will always match more words if it should match an infinite amounts of words and I only give it a finite number of words. Or I will need some more compact representation of the input. Or I am also thinking about giving me some regular expression as input and a list of additional words and I want to get a regular expression which matches all of them together (and maybe more). In any case, it should try to construct a regular expression which is as simple as possible.
What techniques are availalbe which can do that?
I was quite misunderstood. I know the general principles behind regular expressions. I know what it is. And in most cases I can come up quite easily with a regular expression to some language by hand. But I am searching for algorithms which does that.
Again formulated a bit different:
Let L be a regular language. Let M_n be a finite subset of L with n elements. Let M_n be a subset of M_(n+1).
I want to have an algorithm LRE which gets a finite set of words and outputs a regular expression. And I want to have the property:
lim_n->infinity | diff( LRE(M_n), L ) | = 0
| 0
| 0
| 0
| 1
| 0
| 0
|
Is there an open source Java library/algorithm for finding if a particular piece of text is a question or not?
I am working on a question answering system that needs to analyze if the text input by user is a question.
I think the problem can probably be solved by using opensource NLP libraries but its obviously more complicated than simple part of speech tagging. So if someone can instead tell the algorithm for it by using an existing opensource NLP library, that would be good too.
Also let me know if you know a library/toolkit that uses data mining to solve this problem. Although it will be difficult to get sufficient data for training purposes, I will be able to use stack exchange data for training.
| 0
| 1
| 0
| 0
| 0
| 0
|
i ran into a strange problem when trying to flip the y-axis of a coordinate system that im creating:
private AffineTransform getTransform() {
if (transform == null) {
transform = new AffineTransform();
double scaleX = (double) this.getWidth() / (coordinateSystem.getMaxX() - coordinateSystem.getMinY());
double scaleY = (double) this.getHeight() / (coordinateSystem.getMaxY() - coordinateSystem.getMinY());
transform.setToScale(scaleX, scaleY);
double deltaX = (coordinateSystem.getMaxX() - coordinateSystem.getMinX()) / 2;
double deltaY = (coordinateSystem.getMaxY() - coordinateSystem.getMinY()) / 2;
transform.translate(deltaX, deltaY);
}
return transform;
}
The AffineTransform is set to scaling and translation. and everything works fine except that my y-values are inverted (max value is a the bottom of the coordinate system, min value is at the top). I tried switching this by inverting the scale factor for the y axis. but this was not working.
Do i have to let the Transform rotate by PI, to achieve the flipped y axis?
Shouldn't multiplying the scale factor for the y axis by minus 1 be the same?
| 0
| 0
| 0
| 0
| 1
| 0
|
I have some object whish moves by sinusoid. I have to animate it each time it reaches the top (or the bottom) of the "wave". I want to do this with derivative function: as we know it changes the value (from positive to negative or contrary) at that points. So the code is:
// Start value
int functionValue = +1;
// Function
float y = k1 * sinf(k2 * Deg2Rad(x)) + y_base;
// Derivative function
float tempValue = -cosf(y);
// Check whether value is changed
if (tempValue * functionValue < 0)
{
animation = true;
}
functionValue = tempValue;
if I will output the tempValue it shows strange numbers:
0.851513
0.997643
0.0242145
0.690432
0.326303
-0.614262
0.892036
0.1348
0.709843
0.968676
0.0454846
0.920602
-0.423125
0.692132
-0.960107
0.0799654
-0.747722
-0.635241
0.148477
-0.98611
0.900912
-0.877801
0.811632
-0.362743
-0.233856
0.35512
-0.994107
0.885184
-0.468005
0.982489
0.675337
0.661048
0.870765
0.0312914
-0.319066
-0.602956
-0.996169
-0.95627
And animation is strange too. Not only at the top of wave. What's wrong is there?
| 0
| 0
| 0
| 0
| 1
| 0
|
I have to permute N first elements of a singly linked list of length n, randomly. Each element is defined as:
typedef struct E_s
{
struct E_s *next;
}E_t;
I have a root element and I can traverse the whole linked list of size n. What is the most efficient technique to permute only N first elements (starting from root) randomly?
So, given a->b->c->d->e->f->...x->y->z I need to make smth. like f->a->e->c->b->...x->y->z
My specific case:
n-N is about 20% relative to n
I have limited RAM resources, the best algorithm should make it in place
I have to do it in a loop, in many iterations, so the speed does matter
The ideal randomness (uniform distribution) is not required, it's Ok if it's "almost" random
Before making permutations, I traverse the N elements already (for other needs), so maybe I could use this for permutations as well
UPDATE: I found this paper. It states it presents an algorithm of O(log n) stack space and expected O(n log n) time.
| 0
| 0
| 0
| 0
| 1
| 0
|
I am trying to generate a 3d tube along a spline. I have the coördinates of the spline (x1,y1,z1 - x2,y2,z2 - etc) which you can see in the illustration in yellow. At those points I need to generate circles, whose vertices are to be connected at a later stadium. The circles need to be perpendicular to the 'corners' of two line segments of the spline to form a correct tube. Note that the segments are kept low for illustration purpose.
[apparently I'm not allowed to post images so please view the image at this link]
http://img191.imageshack.us/img191/6863/18720019.jpg
I am as far as being able to calculate the vertices of each ring at each point of the spline, but they are all on the same planar ie same angled. I need them to be rotated according to their 'legs' (which A & B are to C for instance).
I've been thinking this over and thought of the following:
two line segments can be seen as 2 vectors (in illustration A & B)
the corner (in illustraton C) is where a ring of vertices need to be calculated
I need to find the planar on which all of the vertices will reside
I then can use this planar (=vector?) to calculate new vectors from the center point, which is C
and find their x,y,z using radius * sin and cos
However, I'm really confused on the math part of this. I read about the dot product but that returns a scalar which I don't know how to apply in this case.
Can someone point me into the right direction?
[edit]
To give a bit more info on the situation:
I need to construct a buffer of floats, which -in groups of 3- describe vertex positions and will be connected by OpenGL ES, given another buffer with indices to form polygons.
To give shape to the tube, I first created an array of floats, which -in groups of 3- describe control points in 3d space.
Then along with a variable for segment density, I pass these control points to a function that uses these control points to create a CatmullRom spline and returns this in the form of another array of floats which -again in groups of 3- describe vertices of the catmull rom spline.
On each of these vertices, I want to create a ring of vertices which also can differ in density (amount of smoothness / vertices per ring).
All former vertices (control points and those that describe the catmull rom spline) are discarded.
Only the vertices that form the tube rings will be passed to OpenGL, which in turn will connect those to form the final tube.
I am as far as being able to create the catmullrom spline, and create rings at the position of its vertices, however, they are all on a planars that are in the same angle, instead of following the splines path.
[/edit]
Thanks!
| 0
| 0
| 0
| 0
| 1
| 0
|
I am creating a database for my local photos with a web interface, where I want to be able tag images and rotate them, amongst other things. When implementing tags (just like Facebook's tagging system) I have come across a problematic area. Namely:
Let's say I have tagged an image of (not) me:
And when I have rotated it, I want the tag coordinates to rotate with the image, like so:
Here is my problem. I store the coordinates in the database (x, y) in the CSS coordinate system, ie left/top instead of the mathematical left/bottom. (It might not be too big of an issue?)
The next big issue is that when I rotate around the center (the point [0,0]) I get negative coordinates. From, for example, [100, 100] to [-100, -100]. This is not correct because when I rotate an image, I don't get negative coordinates. The coordinate system is only positive.
All my rotation code has been using the vector rotation formula:
$nx = $x * cos(deg2rad($rotation_angle)) - $y * sin(deg2rad($rotation_angle));
$ny = $x * sin(deg2rad($rotation_angle)) + $y * cos(deg2rad($rotation_angle));
My question is: How do I solve this? I have tried just using abs to turn the negative values to positive, but it results in the wrong coordinates.
| 0
| 0
| 0
| 0
| 1
| 0
|
I found a formula few months ago, myself to translate any source language (computer characters) to destination (computer characters). Using Lua (desk top users) and C++ class (for native access) so that i can embed it in Web Browser etc etc. I am wondering if we have already better something for this in C++ or Lua.
Mine sometimes its really not translating grammars correctly or even rules, before building it i thought mine would be a best way to complete, but its taking way to long now, and i am afraid it may become wrong implementation. Now i want to check out others and compare mine.
I used Google translate or others which is not my target, i was building a translator engine (like google or others), where someone can put there dictionary and create rules.
Is there any existing translation framework or libraries (OpenCOG or Moses) to do Source language to Destination ?
example: Arabic to Chinese or English to Japanese ? Or What else Google/others using ?
Any suggestion would be appreciated
Thanks in advance.
| 0
| 1
| 0
| 0
| 0
| 0
|
I have to convert all the latin characters to their corresponding English alphabets. Can I use Python to do it? Or is there a mapping available?
Unicode values to non-unicode characters
Ramírez Sánchez should be converted to Ramirez Sanchez.
| 0
| 1
| 0
| 0
| 0
| 0
|
It seems like one's complement representation of signed numbers is the most popular now (and probably the only representation used in the modern hardware). Why is it exactly better than others?
| 0
| 0
| 0
| 0
| 1
| 0
|
I've been thinking about using Markov techniques to restore missing information to natural language text.
Restore all-caps text to mixed-case.
Restore accents / diacritics to languages which should have them but have been converted to plain ASCII.
Convert rough phonetic transcriptions back into native alphabets.
That seems to be in order of least difficult to most difficult. Basically the problem is resolving ambiguities based on context.
I can use Wiktionary as a dictionary and Wikipedia as a corpus using n-grams and Hidden Markov Models to resolve the ambiguities.
Am I on the right track? Are there already some services, libraries, or tools for this sort of thing?
Examples
GEORGE LOST HIS SIM CARD IN THE BUSH ⇨ George lost his SIM card in the bush
tantot il rit a gorge deployee ⇨ tantôt il rit à gorge déployée
| 0
| 1
| 0
| 0
| 0
| 0
|
Every now and then, I hear someone saying things like "functional programming languages are more mathematical". Is it so? If so, why and how? Is, for instance, Scheme more mathematical than Java or C? Or Haskell?
I cannot define precisely what is "mathematical", but I believe you can get the feeling.
Thanks!
| 0
| 0
| 0
| 0
| 1
| 0
|
For some reason this isn't storing the variable correctly giving me a value of "0" after the equation.
if ($power_weight == '') {
$power_weight = NULL;
}
else {
$power_weight = $power_weight / 1.01387 * 2.20462262;
}
echo $power_weight;
When a similar equation works fine
if ($zero_sixty == '') {
$zero_sixty = NULL;
}
else {
$zero_sixty = $zero_sixty * 60 / 62;
}
echo $zero_sixty;
| 0
| 0
| 0
| 0
| 1
| 0
|
I have 1 result and which i will receive in Bank account, Based on that account i have to Put a balance to user account.
How can you find the Handling cost from total tried 491.50 / 0.95 = 517.36 which is wrong ? It should be 500.00 (to my expectation)
User balance requires 500.00
When 500.00 selected he gets 5% discount
There is a handling cost for this
ex:
1) Discount: 500.00 - 5% = 475.00
2) Handling cost: (475.00 x 0.034) + 0.35 = 16.50
3) Total: 475.00 + 16.50 = 491.50
So problem is from 491.50, i have to find atleast handling cost to get promised Balance.
Any solution ? Cant figure it out myself...
In short cut:
a) i put 491.50 -> b) my formula will suggest me apply balance 500.00 (which is the main goal)
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm trying to create an image animation using Raphael JS.
I want the effect of a bee moving randomly across the page, I've got a working example but it's a bit "jittery", and I'm getting this warning in the console:
"Resource interpreted as image but transferred with MIME type text/html"
I'm not sure if the warning is causing the "jittery" movement or its just the way I approached it using maths.
If anyone has a better way to create the effect, or improvements please let me know.
I have a demo online here
and heres my javascript code:
function random(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function BEE(x, y, scale) {
this.x = x;
this.y = y;
this.s = scale;
this.paper = Raphael("head", 915, 250);
this.draw = function() {
this.paper.clear();
this.paper.image("bee.png", this.x, this.y, 159*this.s, 217*this.s);
}
this.update = function() {
var deg = random(-25, 25);
var newX = Math.cos(Raphael.rad(deg)) * 2;
var newY = Math.sin(Raphael.rad(deg)) * 2;
this.x += newX;
this.y += newY;
if( this.x > 915) {
this.x = 0;
}
if( this.y > 250 || this.y < 0 ) {
this.y = 125;
}
}
}
$(document).ready(function() {
var bee = new BEE(100, 150, 0.4);
var timer = setInterval(function(){
bee.draw();
bee.update();
}, 15);
}
| 0
| 0
| 0
| 0
| 1
| 0
|
Long story short, I'm making a platform game. I'm not old enough to have taken Calculus yet, so I know not of derivatives or integrals, but I know of them. The desired behavior is for my character to automagically jump when there is a block to either side of him that is above the one he's standing on; for instance, stairs. This way the player can just hold left / right to climb stairs, instead of having to spam the jump key too.
The issue is with the way I've implemented jumping; I've decided to go mario-style, and allow the player to hold 'jump' longer to jump higher. To do so, I have a 'jump' variable which is added to the player's Y velocity. The jump variable increases to a set value when the 'jump' key is pressed, and decreases very quickly once the 'jump' key is released, but decreases less quickly so long as you hold the 'jump' key down, thus providing continuous acceleration up as long as you hold 'jump.' This also makes for a nice, flowing jump, rather than a visually jarring, abrupt acceleration.
So, in order to account for variable stair height, I want to be able to calculate exactly what value the 'jump' variable should get in order to jump exactly to the height of the stair; preferably no more, no less, though slightly more is permissible. This way the character can jump up steep or shallow flights of stairs without it looking weird or being slow.
There are essentially 5 variables in play:
h -the height the character needs to jump to reach the stair top<br>
j -the jump acceleration variable<br>
v -the vertical velocity of the character<br>
p -the vertical position of the character<br>
d -initial vertical position of the player minus final position<br>
Each timestep:<br>
j -= 1.5; //the jump variable's deceleration<br>
v -= j; //the jump value's influence on vertical speed<br>
v *= 0.95; //friction on the vertical speed<br>
v += 1; //gravity<br>
p += v; //add the vertical speed to the vertical position<br>
v-initial is known to be zero<br>
v-final is known to be zero<br>
p-initial is known<br>
p-final is known<br>
d is known to be p-initial minus p-final<br>
j-final is known to be zero<br>
j-initial is unknown<br>
Given all of these facts, how can I make an equation that will solve for j?
tl;dr How do I Calculus?
Much thanks to anyone who's made it this far and decides to plow through this problem.
Edit: Here's a graph I made of an example in Excel.
I want an equation that will let me find a value for A given a desired value for B.
Since the jump variable decreases over time, the position value isn't just a simple parabola.
| 0
| 0
| 0
| 0
| 1
| 0
|
Could someone please tell what is current state of practical human-like AI development in the world? Which projects reached most success and/or more promising? I only interested in developments which are going to match & exceed human capabilities in terms of thinking and reasoning.
I am not interested in practical narrow cases like translation, speech synthesis & recognition, OCR, robotics.
Pure intelligence is what I am looking for.
| 0
| 1
| 0
| 0
| 0
| 0
|
I have polynomials of nontrivial degree (4+) and need to robustly and efficiently determine whether or not they have a root in the interval [0,T]. The precise location or number of roots don't concern me, I just need to know if there is at least one.
Right now I'm using interval arithmetic as a quick check to see if I can prove that no roots can exist. If I can't, I'm using Jenkins-Traub to solve for all of the polynomial roots. This is obviously inefficient since it's checking for all real roots and finding their exact positions, information I don't end up needing.
Is there a standard algorithm I should be using? If not, are there any other efficient checks I could do before doing a full Jenkins-Traub solve for all roots?
For example, one optimization I could do is to check if my polynomial f(t) has the same sign at 0 and T. If not, there is obviously a root in the interval. If so, I can solve for the roots of f'(t) and evaluate f at all roots of f' in the interval [0,T]. f(t) has no root in that interval if and only if all of these evaluations have the same sign as f(0) and f(T). This reduces the degree of the polynomial I have to root-find by one. Not a huge optimization, but perhaps better than nothing.
| 0
| 0
| 0
| 0
| 1
| 0
|
:Life
set /a R=%random%%%50+1
echo %random% >> %R%.bat
set /a t=%time:~6,-3%
If %t% geq 10 (
set /a t=%t%-10
) else (
set /a t=%t%+10
)
:wait
If %time:~6,-3% neq %t% goto :Wait
:death
set /a K=%random%%%50+1
del /Q %K%.bat
:disease
set /a D=%random%%%150+1
If %D% EQU 150 del /Q *.bat (
goto Life
) else (
If %D% EQU 150 echo On Error Resume Next > temp.vbs
If %D% EQU 150 echo MsgBox "Disease Killed The Biome", vbInformation + vbSystemModal + vbOKOnly, "Life.exe" >> temp.vbs
If %D% EQU 150 cscript temp.vbs
If %D% EQU 150 del temp.vbs
goto Life
)
:EOF
So my issue is the timer engine. The counter itself contains 00–59 but the other is 0–59 so when the ticker hits a number and it has a value of 9 or less it'll skip them on the next passover because they don't have 09 (etc.), is there a way where I can set the code to other ticker to stay at 59 the whole time?
| 0
| 1
| 0
| 0
| 0
| 0
|
Lets assume, for example, that I have a 3-dimensional grid/array where the axis run from 1 to 1000 (or 0 to 999 equivalently). This array has 1000^3 elements.
I would like to map a single integer in the range 0 to 1000^3 to this array in a deterministic way using Java. Preferably this solution would work for any dimension N.
Here is a pseudo-codish example of such a function:
public Vector<int> nthElement( Vector<int> dims, int n )
So if I would call it like nthElement([1000, 1000, 1000], 0) it would return [0, 0, 0] whereas nthElement([1000, 1000, 1000], 1001) would return something like [999, 1, 0].
The solution should be for N dimensions and not for 3 as in my example.
| 0
| 0
| 0
| 0
| 1
| 0
|
I am trying to implement porter stemming algorithm, but I stumbled at this point
where the square brackets denote
arbitrary presence of their contents.
Using (VC){m} to denote VC repeated m
times, this may again be written as
[C](VC){m}[V].
m will be called the \measure\ of any
word or word part when represented in
this form. The case m = 0 covers the
null word. Here are some examples:
m=0 TR, EE, TREE, Y, BY.
m=1 TROUBLE, OATS, TREES, IVY.
m=2 TROUBLES, PRIVATE, OATEN, ORRERY.
I don't understand what is this "measure" and what does it stand for?
| 0
| 1
| 0
| 0
| 0
| 0
|
I'm trying to draw a "targetting ring" on the ground below a "unit" in a hobby 3d game I'm working on. Basically I want to project a bright red patterned ring onto the ground terrain below the unit.
The only approach I can think of is this -
Draw the world once as normal
Draw
the world a second time but in my
vertex shader I have the world x,y,z
coordinates of the vertex and I can
pass in the coordinates of the
highlighted unit - so I can
calculate what the u,v coordinates
in my project texture should be at
that point in the world for that
vertex.
I'd then use the pixel shader to pick pixels from the target ring texture and blend them into the previously drawn world.
I believe that should be easy, and should work but it involves me drawing the whole visible world twice as it's hard to determine exactly which polygons the targetting ring might fall onto. It seems a big overhead to draw the whole world twice, once for the normal lit textured ground, and then again just to draw the targetting ring.
Is there a better approach that I'm missing?
| 0
| 0
| 0
| 0
| 1
| 0
|
I have a random variable X that is a mixture of a binomial and two normals (see what the probability density function would look like (first chart))
and I have another random variable Y of similar shape but with different values for each normally distributed side.
X and Y are also correlated, here's an example of data that could be plausible :
X Y
1. 0 -20
2. -5 2
3. -30 6
4. 7 -2
5. 7 2
As you can see, that was simply to represent that my random variables are either a small positive (often) or a large negative (rare) and have a certain covariance.
My problem is : I would like to be able to sample correlated and random values from these two distributions.
I could use Cholesky decomposition for generating correlated normally distributed random variables, but the random variables we are talking here are not normal but rather a mixture of a binomial and two normals.
Many thanks!
| 0
| 0
| 0
| 0
| 1
| 0
|
I've been skipping math classes, and now I have problems. :)
Can you please explain to me how I should write this expression in Javascript?
Big thanks! :)
| 0
| 0
| 0
| 0
| 1
| 0
|
I am trying to implement porter stemming algorithm, but i am having difficualties understanding this point
Step 1c
(*v*) Y -> I happy -> happi
sky -> sky
Isn't that the the opposite of what we want to do , why does the algorithim convert the Y into I.
for the complete algorithm here http://tartarus.org/~martin/PorterStemmer/def.txt
Thanks
| 0
| 1
| 0
| 0
| 0
| 0
|
I've written a huge page in JavaScript for a tournament I'm hosting on a game. I've gotten everything I really need worked out into arrays, but I want to add rounds. The whole script adjusts to tournament settings (for more in the future) and I'd like this to adjust itself as well. So, let's say the tournament settings are [game,teamsize,entrylimit]. The entrylimit will be the key to finding the solution, because that decides the rounds. It works in a tree system (or however it's called). Let's say the entrylimit is 8. That means the first round will consist of 4 matches, and the second will consist of 2. If the entrylimit were 16, then the first round would consist of 8 matches, the second would consist of 4, and the third would consist of 2. I want to find a way to stick this into my loop where matches are written, and use the entrylimit and match number to generate the round number. All I need is a formula that can use those two variables to get my desired result. Also I apologize for the excessive amount of detail.
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm developing an open-ended strategy game. I am using the following formula to calculate damage:
$rand = rand($a, $b) + $c;
$damage = $rand * sqrt(($d / 20) * $c));
$a, $b, $c, and $d are all values that can be modified by the user over the course of play, either by buying a better item ($a and $b), investing in the item ($c), or investing in their character $d.
What I want to do now is add a bit of randomness to the outcome of the equation. However, because the game is open ended:
a static value would become unnoticeable/negligible over time.
a percentage based value would allow for too much noise over time.
So, I want to add a random value that is small at first, grows with increased input, but has diminishing returns. I'm sure I need some kind of logarithmic formula, but I'm not sure how to go about it!
| 0
| 0
| 0
| 0
| 1
| 0
|
Possible Duplicates:
Big integers in C#
C# unlimited significant decimal digits (arbitrary precision) without java
I read the question at Arbitrary precision decimals in C#? but I don't have the J# library. I need a library for arbitrary precision decimals with C#.
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm looking for ideas/experiences/references/keywords regarding an adaptive-parameter-control of search algorithm parameters (online-learning) in combinatorial-optimization.
A bit more detail:
I have a framework, which is responsible for optimizing a hard combinatorial-optimization-problem. This is done with the help of some "small heuristics" which are used in an iterative manner (large-neighborhood-search; ruin-and-recreate-approach). Every algorithm of these "small heuristics" is taking some external parameters, which are controlling the heuristic-logic in some extent (at the moment: just random values; some kind of noise; diversify the search).
Now i want to have a control-framework for choosing these parameters in a convergence-improving way, as general as possible, so that later additions of new heuristics are possible without changing the parameter-control.
There are at least two general decisions to make:
A: Choose the algorithm-pair (one destroy- and one rebuild-algorithm) which is used in the next iteration.
B: Choose the random parameters of the algorithms.
The only feedback is an evaluation-function of the new-found-solution. That leads me to the topic of reinforcement-learning. Is that the right direction?
Not really a learning-like-behavior, but the simplistic ideas at the moment are:
A: A roulette-wheel-selection according to some performance-value collected during the iterations (near past is more valued than older ones).
So if heuristic 1 did find all the new global best solutions -> high probability of choosing this one.
B: No idea yet. Maybe it's possible to use some non-uniform random values in the range (0,1) and i'm collecting some momentum of the changes.
So if heuristic 1 last time used alpha = 0.3 and found no new best solution, then used 0.6 and found a new best solution -> there is a momentum towards 1
-> next random value is likely to be bigger than 0.3. Possible problems: oscillation!
Things to remark:
- The parameters needed for good convergence of one specific algorithm can change dramatically -> maybe more diversify-operations needed at the beginning, more intensify-operations needed at the end.
- There is a possibility of good synergistic-effects in a specific pair of destroy-/rebuild-algorithm (sometimes called: coupled neighborhoods). How would one recognize something like that? Is that still in the reinforcement-learning-area?
- The different algorithms are controlled by a different number of parameters (some taking 1, some taking 3).
Any ideas, experiences, references (papers), keywords (ml-topics)?
If there are ideas regarding the decision of (b) in a offline-learning-manner. Don't hesitate to mention that.
Thanks for all your input.
Sascha
| 0
| 0
| 0
| 1
| 0
| 0
|
I would like to ask you about this programing part, is it everything ok?
the task was:
Write the pseudocode or flow diagram and code for the theorem of Pythagoras - for right-angle triangle with three ribs (a, b, and c) of type integer
int KendiA = 0;
int KendiB = 0;
int H = 0;
string Trekendeshi = null;
int gjetja = 0;
for (KendiA = 1; KendiA <= 15; KendiA++)
{
for (KendiB = 1; KendiB <= 15; KendiB++)
{
for (H = 1; H <= 30; H++)
{
if ((Math.Pow(KendiA, 2) + Math.Pow(KendiB, 2) == Math.Pow(H, 2)))
{
gjetja = gjetja + 1;
Trekendeshi = gjetja + "\t" + KendiA + "\t" + KendiB + "\t" + H;
Console.WriteLine(Trekendeshi);
}
}
}
}
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm currently working on a game where each unit has a value for health, shields and agility as well as a certain number of six types of weapon.
e.g. Unit B has 2 lasers, 2 heavy lasers, and 1 missile launcher, no ion blaster, no heavy ion blaster, no nuclear missiles, 5 health, 2 shield, and 40 agility.
I have gone through a good 20 different algorithms trying to get MS Excel to balance these all these factors to give the ship a score. My current algorithm works great for some of the smaller units, but gets very unbalanced with the bigger units
Each ship has a damage value, where each type of weaponry is multiplied by the damage of that weapon and added together.
damage = weapon1*damage1 + weapon2*damage2 + ...
The damage value is multiplied by health + 2*shield + 2*agility. Agility and shield are multiplied to give them weight over health (a unit cant lose health if it can't be hit). I also subtract the cost of the unit. So my current equation for one of my units looks like:
value = damage*(health + 2*shield + 2*agility) - 3*cost
Here are some examples:
Unit 1 - 1 laser, 1 health, 93 agility, and costs 1. Total score is 233.
Unit 2 - 2 lasers, a missile launcher, and 3 health, but only 76 agility. Score is 200.
Unit 3 - 6 lasers, 30 health and 15 shields, 37 agility - scores 585.
I want the scores of unit 3 to be higher, but the scores for units 1 and 2 are pretty good. Can anyone suggest a better equation that will smooth out the values?
| 0
| 1
| 0
| 1
| 0
| 0
|
Merry Christmas everyone. I do have a question before Santa arrives.
I'm new with Java, so i'm skimming through my Java book and I'm doing the exercises on my first chapter.
Here's the question,
"Write and application that determines the value of the coins in a jar and prints the total in Dollars and Cents. Read integer values that represent the number of quarters, dimes, nickels and pennies."
I actually did this program. But I wonder if I did it right.
public class PP28 {
public static void main(String[] args) {
// cents = pennies.
double quarters = 0.25 * 40;
double dimes = 0.1 * 200;
double nickels = 0.05 * 400;
double pennies = 0.01 * 150;
int total;
int cent;
total = (int) quarters + (int) dimes + (int) nickels + (int) pennies;
cent = 100 % total;
System.out.println(total+" dollars and "+cent+" cents");
}
}
It compiles and runs fine. Also, I wonder if this is mathematically right? Should I get 49 cents that is almost equivalent to 51.(5)$? Because all quarters, dimes, nickels and pennies has the sum of 51.5 dollars.
| 0
| 0
| 0
| 0
| 1
| 0
|
This is for http://cssfingerprint.com
I have a system (see about page on site for details) where:
I need to output a ranked list, with confidences, of categories that match a particular feature vector
the binary feature vectors are a list of site IDs & whether this session detected a hit
feature vectors are, for a given categorization, somewhat noisy (sites will decay out of history, and people will visit sites they don't normally visit)
categories are a large, non-closed set (user IDs)
my total feature space is approximately 50 million items (URLs)
for any given test, I can only query approx. 0.2% of that space
I can only make the decision of what to query, based on results so far, ~10-30 times, and must do so in <~100ms (though I can take much longer to do post-processing, relevant aggregation, etc)
getting the AI's probability ranking of categories based on results so far is mildly expensive; ideally the decision will depend mostly on a few cheap sql queries
I have training data that can say authoritatively that any two feature vectors are the same category but not that they are different (people sometimes forget their codes and use new ones, thereby making a new user id)
I need an algorithm to determine what features (sites) are most likely to have a high ROI to query (i.e. to better discriminate between plausible-so-far categories [users], and to increase certainty that it's any given one).
This needs to take into balance exploitation (test based on prior test data) and exploration (test stuff that's not been tested enough to find out how it performs).
There's another question that deals with a priori ranking; this one is specifically about a posteriori ranking based on results gathered so far.
Right now, I have little enough data that I can just always test everything that anyone else has ever gotten a hit for, but eventually that won't be the case, at which point this problem will need to be solved.
I imagine that this is a fairly standard problem in AI - having a cheap heuristic for what expensive queries to make - but it wasn't covered in my AI class, so I don't actually know whether there's a standard answer. So, relevant reading that's not too math-heavy would be helpful, as well as suggestions for particular algorithms.
What's a good way to approach this problem?
| 0
| 1
| 0
| 0
| 0
| 0
|
Very simple math question.
Say I have an image with a point being tracked in it. Here are my variables:
Image Height
Image Width
Point (pixles from left) coordinate X
Point (pixles from top) coordinate Y
For example the width, I want it to return a value of -0.5, which represents the distance from the center, such that 1 would be the total right, and -1 would be the total left.
So, how would I calculate so that
The point was (width) a quarter way across the entire frame, or a half way across the left SIDE of the frame. The variables would equal:
Image width: 40
Point X: 10
I know this is basic, but I seriously am having a mind cramp right now O_o.
Thanks,
Christian
| 0
| 0
| 0
| 0
| 1
| 0
|
Curious why my method is behaving differently than doing it manually.
Hi, I'm trying to calculate an X/Y vector (calling it angle here) in code. Don't know hot to do static methods yet, so I'm doing the following in my class:
private var gp:Point = new Point(); //defined at top of file
private function combinept(p1:Point, p2:Point) :Point {
gp.x = p1.x + p2.x;
gp.y = p1.y + p2.y;
return gp;
}
In my movement method, when I call:
this.vel.x = this.vel.x + this.ep.x;
this.vel.y = this.vel.y + this.ep.y;
The object bounces around, a bit crazily of course :)
But When I try:
this.vel = this.combinept(this.vel,this.ep);
Instead, the object isn't visible on screen.. like it got some wild velocity and flew off.
Can you tell me why these would behave differently?
| 0
| 0
| 0
| 0
| 1
| 0
|
I have a sine wave whose parameters I can determine (they are user-input). It's of the form y=a*sin(m*x + t)
I'd like to know whether anyone knows an efficient algorithm to figure out the range of y for a given interval which goes from [0, x] (x is again another input)
For example:
for y = sin(x) (i.e. a=1, t=0, m=1), for the interval [0, 4] I'd like an output like [1, -0.756802]
Please keep in mind, m and t can be anything. Thus, the y-curve does not have to start (or end) at 0 (or 1). It could start anywhere.
Also, please note that x will be discrete.
Any ideas?
PS: I'll use python for implementing the algorithm.
| 0
| 0
| 0
| 0
| 1
| 0
|
How to input such system
into maple so that it would solve it?
BTW we some part of system will be given to us,, which we do not know certently - may be some Ai's may be some Bi's as constants. we do not know how much constants we will get. And we would need from given constants get a soltion for other a's and b's. in real life we will be provided with s as a constant but I hoped for general solution=)
| 0
| 0
| 0
| 0
| 1
| 0
|
∫▒fdf/√(f(f^3 a+6bf+3c))
a, b, c are constant
| 0
| 0
| 0
| 0
| 1
| 0
|
Case 1 (discount 6%):
Subtotal: 750.00
Discount: 45.00
Handling cost: 24.32
21% VAT: 0.00
Total (this is the amount you will deposit): 729.32
Case 2 (discount 7%):
Subtotal: 1250.00
Discount: 87.50
Handling cost: 39.88
21% VAT: 0.00
Total (this is the amount you will deposit): 1202.38
Where i am applying this formula:
(729.32 - 0.35) / 1.034/ 0.94 = 750.00 (<<--- CORRECT ) ?
(1202.38 - 0.35) / 1.034/ 0.93 = 1250.01 (<<--- My problem why not 1250.00) ?
How to correct the 7% formula to get exactly 1250.00 ? Instead of fraction error.
| 0
| 0
| 0
| 0
| 1
| 0
|
I was wondering if there is a formula/trick to calculate what number is to the right or to the left on a standard 6-sided die if you know which number is on top and which is facing you.
Need it to solve a problem, but I don't feel like listing all 24 possibilities in an if-statement...:)
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm doing the first chapter exercises on my Java book and I have been stuck for a problem for a while now. I'll print the question,
prompt/read a double value representing a monetary amount. Then determine the fewest number of each bill and coin needed to represent that amount, starting with the highest (assume that a ten dollar bill is the maximum size needed). For example, if the value entered is 47,63 (forty-seven dollars and sixty-three cents), and the program should print the equivalent amount as:
4 ten dollar bills
1 five dollar bills
2 one dollar bills
2 quarters
1 dimes
0 nickels
3 pennies"
etc.
I'm doing an example exactly as they said in order to get an idea, as you will see in the code. Nevertheless, I managed to print 4 dollars, and I can't figure out how to get "1 five dollar", only 7 dollars (see code).
Please, don't do the whole code for me. I just need some advice in regards to what I said. Thank you.
import java.util.Scanner;
public class PP29 {
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
int amount;
double value;
double test1;
double quarter;
System.out.println("Enter \"double\" value: ");
value = sc.nextDouble();
amount = (int) value / 10; // 47,63 / 10 = 4.
int amount2 = (int) value % 10; // 47 - 40 = 7
quarter = value * 100; // 47,63 * 100 = 4736
int sum = (int) quarter % 100; // 4763 / 100 => 4763-4700 = 63.
System.out.println(amount);
System.out.println(amount2);
}
}
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm trying to render a "3D ribbon" using a single 3D cubic Bézier curve to describe it (the width of the ribbon is some constant). The first and last control points have a normal vector associated with them (which are always perpendicular to the tangents at those points, and describe the surface normal of the ribbon at those points), and I'm trying to smoothly interpolate the normal vector over the course of the curve.
For example, given a curve which forms the letter 'C', with the first and last control points both having surface normals pointing upwards, the ribbon should start flat, parallel to the ground, slowly turn, and then end flat again, facing the same way as the first control point. To do this "smoothly", it would have to face outwards half-way through the curve. At the moment (for this case), I've only been able to get all the surfaces facing upwards (and not outwards in the middle), which creates an ugly transition in the middle.
It's quite hard to explain, I've attached some images below of this example with what it currently looks like (all surfaces facing upwards, sharp flip in the middle) and what it should look like (smooth transition, surfaces slowly rotate round). Silver faces represent the front, black faces the back.
Incorrect, what it currently looks like:
Correct Ribbon http://img211.imageshack.us/img211/4659/ribbonincorrect.th.png
Correct, what it should look like:
Incorrect Ribbon http://img515.imageshack.us/img515/2673/ribboncorrect.th.png
All I really need is to be able to calculate this "hybrid normal vector" for any point on the 3D cubic bézier curve, and I can generate the polygons no problem, but I can't work out how to get them to smoothly rotate round as depicted. Completely stuck as to how to proceed!
| 0
| 0
| 0
| 0
| 1
| 0
|
Perhaps regex is not the best way to parse this, tell me if I it is not. Anyway, here are some examples of what the syntax tree looks like:
(S (CC and))
(SBARTMP (IN once) (NP otherstuff))
(S (S (NP blah (VP blah)) (CC then) (NP blah (VP blah (PP blah))) ))
Anyway, what I am trying to do is pull the connective out (and, then, once, etc) and its corresponding head (CC,IN,CC), which I already know for each syntax tree so it can act as an anchor, and I also need to retrieve its parent (in the first it is S, second SBARTMP, and third it is S), and its siblings, if there are any (in the first none, in the second left hand side sibling, and third left-hand-side and right-hand-side sibling). Anything higher than the parent is not included
my $pos = "(\\\w|-)*";
my $sibling = qr{\s*(\\((?:(?>[^()]+)|(?1))*\\))\s*};
my $connective = "once";
my $re = qr{(\(\w*\s*$sibling*\s*\\(IN\s$connective\\)\s*$sibling*\s*\))};
This code works for things like:
my $test1 = "(X (SBAR-TMP (IN once) (S sdf) (S sdf)))";
my $test2 = "(X (SBAR-TMP (IN once))";
my $test3 = "(X (SBAR-TMP (IN once) (X as))";
my $test4 = "(X (SBAR-TMP (X adsf) (IN once))";
It will throw away the X on top and keep everything else, however, once the siblings have stuff embedded in them then it does not match because the regex does not go deeper.
my $test = "(X (SBAR-TMP (IN once) (MORE stuff (MORE stuff))))";
I am not sure how to account for this. I am kind of new to the extended patterns for Perl, just started learning it. To clarify a bit about what the regex is doing: it looks for the connective within two parentheses and the capital-letter/- combo, looks for a complete parent of the same format closing with two parentheses and then should look for any number of siblings that have all their parentheses paired off.
| 0
| 1
| 0
| 0
| 0
| 0
|
I want to generate Keywords for my CMS.
Does someone know a good PHP Script (or something else) which generates keywords?
I have a HTML Site like this: http://pastebin.com/ZU8vdyeP
| 0
| 1
| 0
| 0
| 0
| 0
|
There exists one very good linear interpolation method. It performs linear interpolation requiring at most one multiply per output sample. I found its description in a third edition of Understanding DSP by Lyons. This method involves a special hold buffer. Given a number of samples to be inserted between any two input samples, it produces output points using linear interpolation. Here, I have rewritten this algorithm using Python:
temp1, temp2 = 0, 0
iL = 1.0 / L
for i in x:
hold = [i-temp1] * L
temp1 = i
for j in hold:
temp2 += j
y.append(temp2 *iL)
where x contains input samples, L is a number of points to be inserted, y will contain output samples.
My question is how to implement such algorithm in ANSI C in a most effective way, e.g. is it possible to avoid the second loop?
NOTE: presented Python code is just to understand how this algorithm works.
UPDATE: here is an example how it works in Python:
x=[]
y=[]
hold=[]
num_points=20
points_inbetween = 2
temp1,temp2=0,0
for i in range(num_points):
x.append( sin(i*2.0*pi * 0.1) )
L = points_inbetween
iL = 1.0/L
for i in x:
hold = [i-temp1] * L
temp1 = i
for j in hold:
temp2 += j
y.append(temp2 * iL)
Let's say x=[.... 10, 20, 30 ....]. Then, if L=1, it will produce [... 10, 15, 20, 25, 30 ...]
| 0
| 0
| 0
| 0
| 1
| 0
|
I had some doubts/questions about the math in Java, so I made a small program a screenshot of which you can see in this link:
http://www.imageshuffle.com/view.php?filename=73doublevsfloat.jpg
How are such numbers even possible?
f / i should be 0.0155 no matter how you look at it
i * f should be 155 no matter how you look at it
i + f should be 101.55
i - f should be 98.45
etc. Same with double.
So what gives? Why is math in Java so incorrect?
| 0
| 0
| 0
| 0
| 1
| 0
|
This is a problem I solved for a course and I was wondering if my solution is correct. I wouldn't normally post a pure mathematics problem, except that I believe that is is incomputable, and hence a computer science problem.
You are given:
P(S) = 10%
P(Theta1 | S) = P(Theta2 | S) = 96%
P(not Theta1 | not S) = P(not Theta2 | not S) = 98%
and no other information besides the usual axioms and definitions of probability theory.
In particular you are given no information about the independence of events.
You are asked to compute P(S | Theta1 and Theta2).
Is this solvable? If not, provide an incomputability proof.
Interesting, hey?
| 0
| 0
| 0
| 0
| 1
| 0
|
I have used "Girard's Theorem" to calculate the area of spherical polygon with great circle edges, as stated in a previous answer.
In most cases, it works fine, but I encounters a negative area case. The coordinate (lon/lat) of those vertices in counterclockwise are (radian):
5.240747351 1.016447132
5.268216612 1.067869338
5.216315614 1.072132414
5.129855176 1.00109075
5.080803026 0.950935874
5.134615486 0.9460488828
and I plotted the polygon using NCL (Sorry, I couldn't post image right now :()
As you can see, the interior angle 4 is nearly 180 degree (179.77708422692623). The calculated excess is -0.16533548347651544 in degree. Any idea? If you need to see code, I can post them later. :)
| 0
| 0
| 0
| 0
| 1
| 0
|
I have a question about the svm_predict() method in libsvm.
The README has this quickstart example code:
>>> y, x = [1,-1], [{1:1, 3:1}, {1:-1,3:-1}]
>>> prob = svm_problem(y, x)
>>> param = svm_parameter('-c 4 -b 1')
>>> m = svm_train(prob, param)
>>> p_label, p_acc, p_val = svm_predict(y, x, m)
Now I understand that y is a list of categories that are associated with the dictionaries in x. I also understand the svm_train part.
The part that does not make sense is that in svm_predict, I am required to provide the 'true values' from y, along with the test data in x. I thought the idea was that I do not know the classifications of the test data ahead of time.
if my training data is:
y = [1, 2, 3]
x = [{1:1}, {1:10}, {1:20}]
but my test data is:
z = [{1:4}, {1:12}, {1:19}]
Then why am I required to pass in true values of z into svm_predict() like:
a, b, c = svm_predict(y, z, m)
I'm not going to know the true values for z--that's what the prediction is for. Should I just put arbitrary classification values for y when I perform a prediction, or am I completely missing something?
Thanks all
| 0
| 0
| 0
| 1
| 0
| 0
|
I found a win, loss, percentage calculator in the forums. The form has a PLACE FOR INPUT
Team Braves
WINS = 96
LOSS 66
a button Compute Percentage
and a text box it should read Braves won 59.259 percent of games.
The program in the forums does not work. Does any one know how to do this? The math should be wins / wins+loss * 100. Pleas HELP
This is in V B
| 0
| 0
| 0
| 0
| 1
| 0
|
Does anyone know a good approach/libs for doing algebraic computations in C++?
I have an application being developed in c++ which needs to do algebraic computation. For now I built a C++ parser that accepts expressions in form of strings like "5 + (2 - MYFUNC(3))" which get tokenized into structs and then converted into postfix notation using the Shunting Yard algorithm and evaluated.
The MYFUNC in these expression are my own defined functions that may do some complex computations.
This is a high performance app, the expressions also have variables that are dynamically replaced with values and the expression is re-evaluated
e.g. var1 + (2 - MYFUNC(var2)) -> with var1 and var2 replaced by some values during the course of the run and re-evaluated
I'm using Linux and so far found Giac library but not sure if it's good, any feedback would be welcome.
How do people generally approach this problem? The main language in this case is C++.
| 0
| 0
| 0
| 0
| 1
| 0
|
Look, for example at AppleScript (and there are plenty of others, some admittedly quite good) which advertise their use of the natural language metaphor. Code is apparently more readable because it can be/is intended to be constructed in English-like sentences, says they. I'm sure there are people who would like nothing better than to program using only English sentences. However, I have doubts about the viability of a language that takes that paradigm too far (excepting niche cases).
So, after a certain reasonable point, is natural-languaginess a benefit or a misfeature? What if the concept is carried to an extreme -- will code necessarily be more readable? Or might it be unnecessarily long, difficult to work with, and just as capable of producing hilarity on the scale of obfuscated Perl, obfuscated C, and eye-twisting Bash script logorrhea?
I am aware of some specialty cases like "Inform" that are almost pure English, but these have a niche that they're not likely to venture out from. I hear and read about how great it would be for code to read more like English sentences, but are there discussions of the possible disadvantages? If everyday language is so clear, simple, clean, lovely, concise, understandable, why did we invent mathematical notation in the first place?
Is it really easier to describe complex instructions accurately and precisely to a machine in natural language, or isn't something closer to mathematical markup a much better choice? Where should that line be drawn? And finally, are you attracted to languages that are touted as resembling English sentences? Should this whole question have just been a one liner:
naturalLanguage > computerishLanguage ? booAndHiss : cheerLoudly;
| 0
| 1
| 0
| 0
| 0
| 0
|
I have $sum and need to calculate the sum minus 15% and then I need to display the original value again.
$sum = 199;
echo "value 1: $sum";
$sum = $sum*0.85;
echo "value 2: $sum";
$foo = $sum*1.15;
echo "value 3: $foo";
This is the result I get:
value 1: 199
value 2: 169.15
value 3: 194.5225
Please tell a very stupid person why this formula is obviously wrong and doesn't return 199 in the last output.
| 0
| 0
| 0
| 0
| 1
| 0
|
I need a function that can give me all possible combinations of a array back.
Example:
$source = array('a', 'b', 'c');
$target = thisiswhatisearch($source);
Now the $target should look like:
array('a','b','c','ab','ac','cb','abc')
I dont need the aa, bb, cc.
I also dont need the the ba, ca, acb.. because the order isn't important to me.
Thanks for any help.
| 0
| 0
| 0
| 0
| 1
| 0
|
I have detected edges in gray image using canny operator. Now want to fit circle/ellipse in edges.
I donot know is there any way in c# to cluster/ linking these edges so that I can find edge boundaries and properties as well known in mAtlab.
regards,
| 0
| 0
| 0
| 0
| 1
| 0
|
Any existing java or matlab library to
do image subtracting with background
image
clear out the shade
do dilate and erode to count out how
many person in a room?
| 0
| 1
| 0
| 0
| 0
| 0
|
Is there any methodology/algorithm for computing phonemes and chronemes of a word(text and not audio)?
| 0
| 1
| 0
| 0
| 0
| 0
|
I'm not trying to make a joke here but I am very confused I been trying to figure this out for like 6 hours straight now got about 20 notepads opened up here, 15 calculators and I cant crunch it I'm always getting too much excess in the end.
Lets explain some variables here we got to work with.
Say we got
2566 min points / 2566 max points
0 min xp / 4835 max xp
There is 2 types of jobs that need to use both variables (points and xp)
Job (1) subtracts 32 points per click and adds 72 xp per click.
Job (2) subtracts 10 points per click and adds 14 xp per click.
I'm trying to figure out how to calculate the excess properly. So it would waste the minimal amount of Job(1)'s to still have enough points to do as much Job(2)'s as it possibly can and still reach max xp.
Thats the thing I dont want to run Job1's until there are no more points left because in doing so, the Job1's will exceeds the maximum XP (2566) and I will never get to do any Job2's.
I want to get the maximum possible Job2's in then using proper calculation achieve or overflow the MaxXP of 2566 with Job1's to always achieve max XP. Pretty much my situation is that I need to get 2566 MaxXP to be able to continue completing jobs. While keeping that in mind I want to place most priority on job2's and only use Job1's to achieve the necessary MaxXP of 2566 to reset the min points to max to redo the process all over. I am trying to automate this.
Here is my equations
amountOfJob1s = (minPoints / 32)
amountOfJob2s = (minPoints / 10)
excessXP = (amountOfJob1s * 72) - maxXP
if excessXP < 0 then break
Results
mustDoJob1s = ???
mustDoJob2s = ???
Thank you if anyone can help me figure this out so I can put a good equation here I'd appreciate it.
Either this is not mathematically possible or I just can't crunch it I do believe I have enough variables.
| 0
| 0
| 0
| 0
| 1
| 0
|
Following on from my previous question, I was wondering if anyone knew of any free (as in beer, as in freedom would be nice but not essential) math(s) parsing libraries for Java. I found one called Jep which used to be open-source (ie: written by the community), but now costs $300 upwards (is this even legal?).
Any help appreciated!
| 0
| 0
| 0
| 0
| 1
| 0
|
What techniques exist that can tell the difference betwen plain common phrases such as "to the", "and the" and set phrases and idioms which have their own lexical meanings such as "pick up", "fall in love", "red herring", "dead end"?
Are there techniques which are successful even without a dictionary, statistical methods HMMs train on large corpora for instance?
Or are there heuristics such as ignoring or weighting down "promiscuous" words which can co-occur with just about any word versus words which occur either alone or in a specific limited set of idiomatic phrases?
If there are such heuristics, how do we take into account set phrases and verbal phrases which do incorporate promiscuous words such as "up" in "beat up", "eat up", "sit up", "think up"?
UPDATE
I've found an interesting paper online: Unsupervised Type and Token Identification of Idiomatic Expressions
| 0
| 1
| 0
| 0
| 0
| 0
|
I am attempting to convert base 16 to base 36. I'm taking md5 hashes and making them have all 0-9a-z.
I searched around and didn't find anything good. Any suggestions for converting hexadecimal to hexatridecimal in c++? Do you guys know any good libraries for doing it?
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm currently to reflect an angle in the Y axis using 'Pi - angle'. The angle system I'm using is in radians, with 0 being east, -Pi/2 being north, Pi/2 being south and +/- Pi being west and when I try using the above method to reflect an angle, it frequently returns values above Pi, outside the range. How can I prevent this from happening?
Thanks,
DLiKS
| 0
| 0
| 0
| 0
| 1
| 0
|
I am making a software that deals with employee trust. I am trying to make a math formula (no need to tell that I am bad in math :) ).
Here is the scenario:
Employee 1 trusts employee 2 = > 20% or 0.2 (average trust of employee 1 with employee 2)
Employee 2 deals with 10 customers => 13% (average - 10 customers trust on Employee 2)
Employee 1 also deals with 7 customers that customers belongs to Employee 2's 10 customers. => 37% ( average 7 customers trust on employee 1)
Employee 1 dealt with 10 customers for last 17 years.
Employee 2 dealt with 7 customers for last 1 years.
Now I want to calculate that how can we say that Employee 1 is much trust worthy than Employee 2? If I just see average than I can say Employee 1 but he only dealt with customers for 1 year. Now I want to make a generic formula to see which one is more trust worthy and I want to use all three values that are ( employee to employee, employee to customer, and number of year) to calculate average percentage. I want to increase or decrease an employee trust based on these values. Please remember I want to decrease as well for some employee I can not say that all employee or 90+ employee are trust worthy etc.
What I did:
I just simply plus employee to employee and employee to customer trust weight
Employee 1 = 0.57
Employee 2 = 0.33
I don't know what to do for years.
Current system just calculate employee to employee trust that is not good enough to trust itself.
I am not restricted to any programming language because I just want to make a generic formula. All ideas and suggestions are most welcome !
If you think my problem relates to any previously developed trust model then please do let me know (I already know web trust model but I don't know how to fit that in my situation)
| 0
| 0
| 0
| 0
| 1
| 0
|
Lets say I have this data set...
var a = [5,6,7];
var b = [9,8,6];
Imagine that those values were plotted the y in a (x,y) coordinate pair, and the x was the array index, how could I tell if my two arrays had crossed at one point.
Thanks.
| 0
| 0
| 0
| 0
| 1
| 0
|
In the top of the diagrams below we can see some value (y-axis) changing over time (x-axis).
As this happens we are sampling the value at different and unpredictable times, also we are alternating the sampling between two data sets, indicated by red and blue.
When computing the value at any time, we expect that both red and blue data sets will return similar values. However as shown in the three smaller boxes this is not the case. Viewed over time the values from each data set (red and blue) will appear to diverge and then converge about the original value.
Initially I used linear interpolation to obtain a value, next I tried using Catmull-Rom interpolation. The former results in a values come close together and then drift apart between each data point; the latter results in values which remain closer, but where the average error is greater.
Can anyone suggest another strategy or interpolation method which will provide greater smoothing (perhaps by using a greater number of sample points from each data set)?
| 0
| 0
| 0
| 0
| 1
| 0
|
Do I have make my own Point and Vector types to overload them ? Why does this not work ?
namespace System . windows
{
public partial struct Point : IFormattable
{
public static Point operator * ( Point P , double D )
{
Point Po = new Point ( );
return Po;
}
}
}
namespace SilverlightApplication36
{
public partial class MainPage : UserControl
{
public static void ShrinkingRectangle ( WriteableBitmap wBM , int x1 , int y1 , int x2 , int y2 , Color C )
{
wBM . DrawRectangle ( x1 , y1 , x2 , y2 , Colors . Red );
Point Center = Mean ( x1 , y1 , x2 , y2 );
wBM . SetPixel ( Center , Colors.Blue , 3 );
Point P1 = new Point ( x1 , y1 );
Point P2 = new Point ( x1 , y2 );
Point P3 = new Point ( x1 , y2 );
Point P4 = new Point ( x2 , y1 );
const int Steps = 10;
for ( int i = 0 ; i < Steps ; i++ )
{
double iF = (double)(i+1) / (double)Steps;
double jF = ( 1.0 - iF );
Point P11 = **P1 * jF;**
}
}
| 0
| 0
| 0
| 0
| 1
| 0
|
How do I create a vector like this:
a = [a_1;a_2;...,a_n];
aNew = [a;a.^2;a.^3;...;a.^T].
Is it possible to create aNew without a loop?
| 0
| 0
| 0
| 0
| 1
| 0
|
i am programming a small game for quite some time. We started coding a small FPS-Shooter inside of a project at school to get a bit experience using directX.
I dont know why, but i couldnt stop the project and started programming at home aswell. At the moment i am trying to create some small AI. Of cause thats definatlly not easy, but thats my personal goal anyways. The topic could prolly fill multiple books hehe.
I've got the walking part of my bots done so far. They walk along a scriped path. I am not working on the "aiming" of the bots.
While programming that i hit on some math problem i couldnt solve yet. I hope of your input on this to help me get further. Concepts, ideas and everything else are highly appreciated.
Problem:
Calculate the position (D3DXVECTOR3) where the curve of the projectile (depends on gravity, speed), hit the curved of the enemys walking path (depends on speed). We assume that the enemy walks in a constant line.
Known variables:
float projectilSpeed = 2000 m/s //speed of the projectile per second
float gravitation = 9.81 m/s^2 //of cause the gravity lol
D3DXVECTOR3 targetPosition //position of the target stored in a vector (x,y,z)
D3DXVECTOR3 projectilePosition //position of the projectile
D3DXVECTOR3 targetSpeed //stores the change of the targets position in the last second
Variabledefinition
ProjectilePosition at time of collision = ProjectilePos_t
TargetPosition at time of collision = TargetPos_t
ProjectilePosition at time 0, now = ProjectilePos_0
TargetPosition at time 0, now = TargetPos_0
Time to impact = t
Aim-angle = theta
My try:
Found a formular to calculate "drop" (Drop of the projectile based on the gravity) on Wikipedia:
float drop = 0.5f * gravity * t * t
The speed of the projectile has a horizontal and a vertical part.. Found a formular for that on wikipedia aswell:
ProjectilVelocity.x = projectilSpeed * cos(theta)
ProjectilVelocity.y = projectilSpeed * sin(theta)
So i would assume this is true for the projectile curve:
ProjectilePos_t.x = ProjectilePos_0.x + ProjectileSpeed * t
ProjectilePos_t.y = ProjectilePos_0.y + ProjectileSpeed * t + 0.5f * gravity * t * t
ProjectilePos_t.z = ProjectilePos_0.z + ProjectileSpeed * t
The target walk with a constant speed, so we can determine his curve by this:
TargetPos_t = TargetPos_0 + TargetSpeed * D3DXVECTOR3(t, t, t)
Now i dont know how to continue. I have to solve it somehow to get a hold on the time to impact somehow.
As a basic formular i could use:
float time = distanz / projectileSpeed
But that wouldnt be truly correct as it would assume a linear "Trajectory". We just find this behaivor when using a rocket.
I hope i was able to explain the problem as much as possible. If there are questions left, feel free to ask me!
Greets from germany,
Frank
Edit:
The main problem is that i cant calculate the enemies position at collision time as i dont have the time passed until the collision occurs.. And on the other hand i cant calculate the time without knowing the enemies location at impact time. Maybe an iterative method solves this.
curve enemy:
pos(t).x = pos(0).x + speed.x * time
pos(t).y = pos(0).y + speed.y * time
pos(t).z = pos(0).z + speed.z * time
curve projectile:
pos(t).y = pos(0).y + sin(theta) * speed + 0.5 * gravity * time * time
pos(t).x and pos(t).z not sure how to calculate in (x and z) define the forward direction basically.. not just x..
cant calculate the enemy without knowing the time.. and i cant calculate the time without knowing the angles (theta, pitch/yaw) and the distance it will be to the "future" impact point
| 0
| 0
| 0
| 0
| 1
| 0
|
could you please provide me with some information (or suggest an article) on good collision detection algorithm for 2D non convex figures?
Thanks!
| 0
| 0
| 0
| 0
| 1
| 0
|
How can i do so numb's last 2 numbers randoms like "text's" last 2?
I can't do it with, document.write(str.substr(-2)); beacause its two divs..
How do i do?
<div id="numb">72-450 04 <script type="text/javascript">
document.write(Math.floor(Math.random()*90) +10);
</script></div>
<div id="text">
49</div>
| 0
| 0
| 0
| 0
| 1
| 0
|
Suppose I have some arbitrary input image with width w1 and height h1. I want to rotate this image all the way around 360 degrees back to the starting position. However, if the image is of anything except a circle, then the edges of the image will be clipped if the canvas it is drawn onto remains at size w1 by h1.
What I need then is to determine the canvas size (width w2 and height h2) that can be used for all rotated versions of the input image. I know that w2 == h2, and thus the desired canvas size is a square, because it is obvious that we are rotating something about a center point, and the final image (after 360 rotations) is essentially a circle.
The other thing to consider is that objects such as squares will have corners that will stick out, so just using the max value of width or height for both dimensions also does not work.
One solution I have come up with is to create the canvas larger than I need (for example by setting w2 and h2 to max(w1, h1) * 2, rotating everything, and then trimming all the transparent pixels. This is not very efficient and I would much rather be able to calculate the tightest bounding box upfront.
| 0
| 0
| 0
| 0
| 1
| 0
|
Trying to compute the left and top of a page element.
The element needs to be positioned on an imaginary line that runs from 0,0 of the page window to a point (roughly) equal to 425 pixels from the beginning of the line.
The slope of the line is -.375.
How can I calc the left and top using php?
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm trying to write a simple text mining application to try to tell a German word's gender and plural form.
So, first of all, I need a big wordlist for training. I've searched around but could not find any list having either gender nor plural.
| 0
| 1
| 0
| 0
| 0
| 0
|
<script>
function makeid()
{
var text = "var text = document.write(lastNumber);";
var possible = "*+-/";
for( var i=0; i < 1; i++ )
document.write(lastNumber + possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
document.write(makeid(1))</script>
How do i make this to type for ex: 23* 45- 13/ and so on.
What is wrong?
It just show me 2 numbers and no char after.
| 0
| 0
| 0
| 0
| 1
| 0
|
I'm not even quite sure what terms I should be using for what I want, so any advice on what I'm even asking for would be very welcome.
Basically, my web site lists user-generated accommodations. Each has a rent price, which users will be able to query in our new faceted search box.
Users search by city, and within each city I'd like to present a different rent grouping. That is to say that in City #1, if we have listings ranging from $200 - $1000, I'd like to present checkboxes for:
less than $300
$301 - $500
$501 - $700
more than $700
However, if City #2 has values that range from $500 - $1500, I want the ranges above to change accordingly. So, if I say that I want 5 or 6 range options in each city, I think I have two options:
Take the min and max values and just split the difference. I don't like this idea because one listing with a rent of $10,000 will throw the whole scale off.
Intelligently calculate the ranges using means, medians etc.
Number 2 is what I need help with. I'm a web developer that gets logic, but was never strong on math and statistics at school. Can anyone point me towards a guide that'll help me figure this out?
| 0
| 0
| 0
| 0
| 1
| 0
|
What are common approaches for translating certain words (or expressions) inside a given text, when the text must be reconstructed (with punctuations and everythin.) ?
The translation comes from a lookup table, and covers words, collocations, and emoticons like L33t, CUL8R, :-), etc.
Simple string search-and-replace is not enough since it can replace part of longer words (cat > dog ≠> caterpillar > dogerpillar).
Assume the following input:
s = "dogbert, started a dilbert dilbertion proces cat-bert :-)"
after translation, i should receive something like:
result = "anna, started a george dilbertion process cat-bert smiley"
I can't simply tokenize, since i loose punctuations and word positions.
Regular expressions, works for normal words, but don't catch special expressions like the smiley :-) but it does .
re.sub(r'\bword\b','translation',s) ==> translation
re.sub(r'\b:-\)\b','smiley',s) ==> :-)
for now i'm using the above mentioned regex, and simple replace for the non-alphanumeric words, but it's far from being bulletproof.
(p.s. i'm using python)
| 0
| 1
| 0
| 0
| 0
| 0
|
I'm reading Paradigms of Artificial Intelligence Programming (PAIP) by Peter Norvig and I'm trying to write all the code in Clojure rather than common Lisp. However I'm stuck on this piece of code on page 39:
(defparameter *simple-grammar*
'((sentence -> (noun-phrase verb-phrase))
(noun-phrase -> (Article Noun))
(verb-phrase -> (Verb noun-phrase))
(Article -> the a)
(Noun -> man ball woman table)
(Verb -> hit took saw liked))
"A grammar for a trivial subset of English.")
(defvar *grammar* *simple-grammar*)
How can I translate this into Clojure?
Thanks.
| 0
| 1
| 0
| 0
| 0
| 0
|
In how many different ways can a cube be painted by using three different colors of paint?
The answer of this is 45,
What if I change cube to cuboid?
Thanks!
I am preparing for job interview and this question is from CareeCup.
| 0
| 0
| 0
| 0
| 1
| 0
|
I need some help finding the error in my javascript calculation.
I need to calculate the sum of my input boxes automatically and have my user be able to edit the calculation using + or - buttons.
The code I have already does the calculation automatically if you manually enter the numbers, but pressing the + or - does not change the calculation.
Here is the code:
<html>
<head>
<script language="javascript">
function Calc(className){
var elements = document.getElementsByClassName(className);
var total = 0;
for(var i = 0; i < elements.length; ++i){
total += parseInt(elements[i].value);
}
document.form0.total.value = total;
}
function addone(field) {
field.value = Number(field.value) + 1;
}
function subtractone(field) {
field.value = Number(field.value) - 1;
}
</script>
</head>
<body>
<form name="form0" id="form0">
1: <input type="text" name="box1" id="box1" class="add" value="0" onKeyUp="Calc('add')" onChange="updatesum()" onClick="this.focus();this.select();" />
<input type="button" value=" + " onclick="addone(box1);">
<input type="button" value=" - " onclick="subtractone(box1);">
<br />
2: <input type="text" name="box2" id="box2" class="add" value="0" onKeyUp="Calc('add')" onClick="this.focus();this.select();" />
<input type="button" value=" + " onclick="addone(box2);">
<input type="button" value=" - " onclick="subtractone(box2);">
<br />
3: <input type="text" name="box3" id="box3" class="add" value="0" onKeyUp="Calc('add')" onClick="this.focus();this.select();" />
<input type="button" value=" + " onclick="addone(box3);">
<input type="button" value=" - " onclick="subtractone(box3);">
<br />
<br />
Total: <input readonly style="border:0px; font-size:14; color:red;" id="total" name="total">
</form>
</body></html>
Im sure the issue must be small, I just cant put my finger on it.
| 0
| 0
| 0
| 0
| 1
| 0
|
Hi the aim is to parse a sizeable corpus like wikipedia to generate the most probable parse tree,and named entity recognition. Which is the best library to achieve this in terms of performance and accuracy? Has anyone used more than one of the above libraries?
| 0
| 1
| 0
| 0
| 0
| 0
|
Now, I haven't applied myself to functional programming for, oh, nearly 20 years, when we didn't get much further than writing factorials and fibs, so I'm really appealing to the community for some help in finding a solution.
My problem is this:
"Given a group of trade objects, I want to find all the combinations of trades that net to zero +/- some tolerance."
My starter for ten is:
let NettedOutTrades trades tolerance = ...
Let's assume my starting point is a previously constructed array of tuples (trade, value). What I want back is an array (or list, whatever) of arrays of trades that net out. Thus:
let result = NettedOutTrades [| (t1, -10); (t2, 6); (t3, 6); (t4; 5) |] 1
would result in:
[|
[| t1; t2; t4 |]
[| t1; t3; t4 |]
|]
I'm thinking that this could be achieved with a tail recursive construct, using two accumulators - one for the results and one for the sum of trade values. But how to put it all together...?
I'm sure I could knock out something procedural using c#, but it just doesn't feel like the right tool for the job - I'm convinced there's going to be an elegant, concise, efficient solution using the functional paradigm...I'm just not well practiced enough to identify it at present!
| 0
| 0
| 0
| 0
| 1
| 0
|
Here is my problem:
Given x, y, z and ratio where z is known and ratio is known and is a float representing a relative value, I need to find x and y.
I know that:
x / y == ratio
y - x == z
What I'm trying to do is make my own scroll pane and I'm figuring out the scrollbar parameters.
So for example,
If the scrollbar must be able to scroll 100 values (z) and the thumb must consume 80% of the bar (ratio = 0.8) then x would be 400 and y would be 500.
Thanks
| 0
| 0
| 0
| 0
| 1
| 0
|
I have this polar function:
r = A / log(B * tan(t / 2 * N)
where A, B, N are arbitrary parameters and t is the angle theta in the polar coordinate system.
Example graph for A=8, B=0.5, N=4
How can I plot this function onto a Cartesian coordinate grid so I get an image like the one above?
thanks
| 0
| 0
| 0
| 0
| 1
| 0
|
This is the chars: "*+-/";
Javascript getElementById
How can i do "randt" to be 1 random char?
So if i type:
document.getElementById("sms-text").innerHTML = "" + random2 + randt;
It will be for ex "22*" or "51+"
How do i do it?
| 0
| 0
| 0
| 0
| 1
| 0
|
If I have a very short string, say (JavaScript):
var = "abcd";
and I want to get a random character from it, I could use:
var random_char = str.charAt( Math.floor(Math.random() * str.length) );
Now Math.floor(Math.random() * str.length) returns a random number in the range [0..3].
Can the perceived randomness of the returned character be increased by multiplying the string, i.e. by effectively increasing the range of the random numbers?
var = "abcdabcdabcdabcdabcdabcd";
| 0
| 0
| 0
| 0
| 1
| 0
|
I can't imagine a "clean" or efficient method of doing this.
I would like to transform a string of numbers like @"1234" into an array of shorts for a calculator pet project*.
I think of getting substrings and then the intValue of the substring but it sounds cumbersome and overkill. Would there be a more elegant way of doing it?
Thanks in advance!
* I know that there are more efficient ways to do maths and plenty of C libraries do this but it's for my own education :-).
| 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.