As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I can do it with pen & paper but I'm having a really hard time trying to build methods in ruby that calculates simple formulas like the one below.
How can I build a method in ruby that returns CET?
(To make it easier consider (dj-d0)/365 equals j)
This can be translated almost literally to Ruby if you know the structures to use:
sum = (1..n).inject(0) do |s, j|
fc[j] / ((1 + cet) ** (d[j] - d[0]) / 365) - fc[0]
end
If you want to solve for something, that's another story. You might want to try Mathematica.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
i made this code can anybody tell me is this right how can i verify it.
I=imread('cameraman.tif');
[M N]=size(I);
for i=2:M-1
for j=2:N-1
x=I(i-1,j);
y=I(i+1,j);
z=I(i,j-1);
zz=I(i,j+1);
A=[x y z zz];
J(i,j)=median(A);
end
end
In general, the only way you can discover whether it does what you expect is to try whether it works. #Maroun already described this.
Here are some of the things I noticed:
I believe the code has no techical problems.
I am no expert on the topic but it would surprise me if you don't want to consider the middle point I(i,j) when determining the median. Now you just check left right up and down. Besides this you may want to evaluate the upleft upright downleft and downright. This is a choice however.
Another thing to notice is that currently your result will be smaller than the original image. Probably you want to start with J=I or J = NaN(size(I));
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I don't understand why a PRNG is easier to program than a true RNG. Shouldn't a typical processor make short work of producing a truly random number?
Computers are deterministic machines, given the same input, code included, they will produce the same result. To get true randomness you need to introduce something random from the real world, like the time or cosmic rays or something else that you can't predict.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
In the Python community, the term pythonic refers to idiomatic Python[1]. Is there an equivalent term in the Ruby community for idiomatic Ruby[2]?
[1] For example, using enumerate(l) instead of range(len(l)) is pythonic.
[2] For example, using .each instead of for is idiomatic Ruby.
I've not heard of any such shorthand, presumably because there's no convenient suffix you can append to Ruby to turn it into an adjective :)
If you say something's idiomatic, and you're around rubyists, I think everybody will know what you mean.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Trying to master Ruby (not rails yet). What book would you recommend reading next?
Pickaxe
Well Grounded Rubyist
?
My background... I have a CS degree, I feel like I have absorbed the first two books and am getting quite comfortable with Ruby. I want to get better at the Ruby language before I head into Rails.
Next I'd recommend "Eloquent Ruby" (Russ Olsen) and "Ruby Best Practices" (Greg Brown).
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Is there a hash function that is stable to small changes in text? I'm looking for the opposite of a cryptographic hash, where small changes in the source lead to huge changes in the result.
Something like a perceptual hash for text. Is there such a thing?
Edited: by "small changes in text" I mean changes in punctuation, correction of ortographic / grammatical mistakes, etc. The text itself is an article, like a wikipedia entry (but it can be much smaller, like 2 or 3 paragraphs).
Bonus points if somebody can point to a Python implementation.
You're looking for locality sensitive hashing.