numerical

How to convert a column of string to numerical?

萝らか妹 提交于 2019-12-04 04:02:28
问题 I have this pandas dataframe from a query: | name | event | ---------------------------- | name_1 | event_1 | | name_1 | event_2 | | name_2 | event_1 | I need to convert the column event to numerical, or something to look like this: | name | event_1 | event_2 | ------------------------------- | name_1 | 1 | 0 | | name_1 | 0 | 1 | | name_2 | 1 | 0 | In the software rapidminer, i can do this with an operator "nominal to numerical", so i assume that in python convert the type of the column

logsumexp implementation in C?

坚强是说给别人听的谎言 提交于 2019-12-04 02:55:51
Does anybody know of an open source numerical C library that provides the logsumexp -function? The logsumexp(a) function computes the sum of exponentials log(e^{a_1}+...e^{a_n}) of the components of the array a, avoiding numerical overflow. Here's a very simple implementation from scratch (tested, at least minimally): double logsumexp(double nums[], size_t ct) { double max_exp = nums[0], sum = 0.0; size_t i; for (i = 1 ; i < ct ; i++) if (nums[i] > max_exp) max_exp = nums[i]; for (i = 0; i < ct ; i++) sum += exp(nums[i] - max_exp); return log(sum) + max_exp; } This does the trick of

What is the limit of the Value Type BigInteger in C#?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 01:33:30
As described in MSDN BigInteger is : An immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds. As I can see BigInteger is a ValueType , as much as I know, a ValueType must have a maximum size of 16 bytes . MSDN goes further saying : an OutOfMemoryException can be thrown for any operation that causes a BigInteger value to grow too large. and more : Although this process is transparent to the caller, it does incur a performance penalty. In some cases, especially when repeated operations are performed in a loop on very large BigInteger

Test if a floating point number is an integer

喜夏-厌秋 提交于 2019-12-03 22:46:58
This code works (C# 3) double d; if(d == (double)(int)d) ...; Is there a better way to do this? For extraneous reasons I want to avoid the double cast so; what nice ways exist other than this? (even if they aren't as good) Note: Several people pointed out the (important) point that == is often problematic regrading floating point. In this cases I expect values in the range of 0 to a few hundred and they are supposed to be integers (non ints are errors) so if those points "shouldn't" be an issue for me. d == Math.Floor(d) does the same thing in other words. NB: Hopefully you're aware that you

When to use Fixed Point these days

流过昼夜 提交于 2019-12-03 22:19:22
For intense number-crunching i'm considering using fixed point instead of floating point. Of course it'll matter how many bytes the fixed point type is in size, on what CPU it'll be running on, if i can use (for Intel) the MMX or SSE or whatever new things come up... I'm wondering if these days when floating point runs faster than ever, is it ever worth considering fixed point? Are there general rules of thumb where we can say it'll matter by more than a few percent? What is the overview from 35,000 feet of numerical performance? (BTW, i'm assuming a general CPU as found in most computers, not

Numerical integration in C++

时间秒杀一切 提交于 2019-12-03 20:21:34
问题 I need to integrate a function (of two variables). I know I can do it by using Fubini theorem to integrate one variable functions, then using numerical methods such as the Rectangle method or the Trapezoidal rule . But are there any pre-built functions to do that in C++ ? I need to integrate over the unit R2 triangle ((0,0), (1,0), (0,1)) . 回答1: You can use the GNU Scientific Library, which supports many "Numerical analysis" functions including integration. A very simple example of

How can I add floats together in different orders, and always get the same total?

我们两清 提交于 2019-12-03 14:28:40
Let's say I have three 32-bit floating point values, a , b , and c , such that (a + b) + c != a + (b + c) . Is there a summation algorithm, perhaps similar to Kahan summation , that guarantees that these values can be summed in any order and always arrive at the exact same (fairly accurate) total? I'm looking for the general case (i.e. not a solution that only deals with 3 numbers). Is arbitrary precision arithmetic the only way to go? I'm dealing with very large data sets, so I'd like to avoid the overhead of using arbitrary precision arithmetic if possible. Thanks! There's an interesting

QP solver for Java [closed]

与世无争的帅哥 提交于 2019-12-03 07:44:09
I'm looking for a good easy to use Java based Quadratic Programming (QP) solver. Googling around I came across ojAlgo ( http://ojalgo.org ). However, I was wondering if there are any other/better alternatives. Have a look at Apache Commons Math . I haven't used ojalgo, and I really can't say I've used Commons Lang enough to be able to provide you with a lot of details, but it did do what I needed. Description from their website: Commons Math is a library of lightweight, self-contained mathematics and statistics components addressing the most common problems not available in the Java

Identifying common periodic waveforms (square, sine, sawtooth, …)

[亡魂溺海] 提交于 2019-12-03 07:29:15
Without any user interaction, how would a program identify what type of waveform is present in a recording from an ADC? For the sake of this question: triangle, square, sine, half-sine, or sawtooth waves of constant frequency. Level and frequency are arbitrary, and they will have noise, small amounts of distortion, and other imperfections. I'll propose a few (naive) ideas, too, and you can vote them up or down. You definitely want to start by taking an autocorrelation to find the fundamental. With that, take one period (approximately) of the waveform. Now take a DFT of that signal, and

Generate letters to represent number using ruby?

旧街凉风 提交于 2019-12-03 05:06:57
问题 I would like to generate a sequence of letters i.e. "A", "DE" "GJE", etc. that correspond to a number. The first 26 are pretty easy so 3 returns "C", 26 returns "Z", and 27 would return "AA", 28 "AB", and so on. The thing I can't quite figure out is how to do this so it will handle any number passed in. So if I pass in 4123 I should get back some combination of 3 letters since (26 * 26 * 26) allows for up to +17,000 combinations. Any suggestions? 回答1: class Numeric Alph = ("a".."z").to_a def