numerical-methods

Statsmodels logistic regression convergence problems

大憨熊 提交于 2020-01-02 13:37:12
问题 I'm trying to run a logistic regression in statsmodels on a large design matrix (~200 columns). The features include a number of interactions, categorical features and semi-sparse (70%) integer features. Although my design matrix is not actually ill-conditioned, it seems to be somewhat close (according to numpy.linalg.matrix_rank , it is full-rank with tol=1e-3 but not with tol=1e-2 ). As a result, I'm struggling to get logistic regression to converge with any of the methods in statsmodels.

Python Numerical Integration for Volume of Region

微笑、不失礼 提交于 2020-01-02 03:06:25
问题 For a program, I need an algorithm to very quickly compute the volume of a solid. This shape is specified by a function that, given a point P(x,y,z), returns 1 if P is a point of the solid and 0 if P is not a point of the solid. I have tried using numpy using the following test: import numpy from scipy.integrate import * def integrand(x,y,z): if x**2. + y**2. + z**2. <=1.: return 1. else: return 0. g=lambda x: -2. f=lambda x: 2. q=lambda x,y: -2. r=lambda x,y: 2. I=tplquad(integrand,-2.,2.,g

Robust polygon normal calculation

﹥>﹥吖頭↗ 提交于 2020-01-02 01:22:11
问题 is there a good robust algorithm to calculate normal vector of a convex polygon (in 3D, of course)? For triangles, it is easy: one takes two of the triangle's edges and calculates the cross product: vec3 u = point[0] - point[1], v = point[0] - point[2]; vec3 n = normalize(cross(u, v)); But this approach does not really extend to polygons very well. Some edges of the polygon can be nearly or "exactly" collinear (this will happen often in meshes where T-Junction removal took place), therefore

Trying to simulate a 1-dimensional wave

南笙酒味 提交于 2020-01-01 09:42:32
问题 I'm trying to make a simplified simulation of a 1-dimensional wave with a chain of harmonic oscillators. The differential equation for the position x[i] of the i-th oscillator (assuming equilibrium at x[i]=0 ) turns out to be - according to textbooks - this one: m*x[i]''=-k(2*x[i]-x[i-1]-x[i+1]) (the derivative is wrt the time) so i tried to numerically compute the dynamics with the following algorithm. Here osc[i] is the i-th oscillator as an object with attributes loc (absolute location),

Trying to simulate a 1-dimensional wave

徘徊边缘 提交于 2020-01-01 09:41:09
问题 I'm trying to make a simplified simulation of a 1-dimensional wave with a chain of harmonic oscillators. The differential equation for the position x[i] of the i-th oscillator (assuming equilibrium at x[i]=0 ) turns out to be - according to textbooks - this one: m*x[i]''=-k(2*x[i]-x[i-1]-x[i+1]) (the derivative is wrt the time) so i tried to numerically compute the dynamics with the following algorithm. Here osc[i] is the i-th oscillator as an object with attributes loc (absolute location),

Accept Numerical Values only for input using scanf

我的未来我决定 提交于 2019-12-30 07:18:20
问题 How can I make sure the user inputs numerical values only instead of alphanumeric or any other character? Also what to look for to insert error message for incorrent input? #include<stdio.h> int main() { int a, b, c; printf("Enter first number to add\n"); scanf("%d",&a); printf("Enter second number to add\n"); scanf("%d",&b); c = a + b; printf("Sum of entered numbers = %d\n",c); return 0; } 回答1: If you really want to deal with user input that could be hostile use a separate function for

How can I plot the derivative of a graph in gnuplot?

给你一囗甜甜゛ 提交于 2019-12-30 03:01:07
问题 I have a set of measurements of a variable over time. I have these measurements in a file called "results" with this format: # time sample 0 5 12 43 234 342 etc... I can easily plot this in gnuplot with: plot "results" Is there any way to plot the derivative of these measurements with regard to time (i.e. dsample/dt) directly from gnuplot, or do I have to calculate the derivative separately and plot that directly in gnuplot? 回答1: You can do it by defining a function to take the derivative: #!

Where do I find the machine epsilon in C#?

百般思念 提交于 2019-12-30 00:58:10
问题 The machine epsilon is canonically defined as the smallest number which added to one, gives a result different from one. There is a Double.Epsilon but the name is very misleading: it is the smallest (denormalized) Double value representable, and thus useless for any kind of numeric programming. I'd like to get the true epsilon for the Double type, so that not to have to hardcode tolerances into my program. How do I do this ? 回答1: It's(on my machine): 1.11022302462516E-16 You can easily

sparse matrix library for C++ [closed]

二次信任 提交于 2019-12-29 04:58:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 12 months ago . Is there any sparse matrix library that can do these: solve linear algebraic equations support operations like matrix-matrix/number multiplication/addition/subtraction,matrix transposition, get a row/column of a matrix,and so on matrix size could be 40k*40k or bigger,like 250k*250k fast can be used in Windows

Solving a System of Linear Equations with Constraints in C# (Mono)

最后都变了- 提交于 2019-12-25 02:23:17
问题 I have a system of linear equations with dimensions 3xN that I am currently solving using the Accord.NET method: double[,] A = ... // matrix A double[] b = ... // vector b // Then all that is necessary is to call: double[] x = A.Solve(b, leastSquares: true); This works fine but I need to also impose constraints (primarily, x > 0). Is there a way to implement this (ideally within Accord or some other simple library)? The elements of both A and B can have positive, negative and zero values and