C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

Generating simulation data based on a specified distribution

By : tmacrina
Date : November 22 2020, 01:01 AM
wish helps you I hate to be that guy who answers their own post but I just found the same example used on page 15 here in the "rpart" documentation. I'll continue writing up the answer but I'll delete the question at the end of the day unless I hear differently from the community. Sorry about my oversight.
code :
``````# the data for this example is generated by a malfunctioning calculator
set.seed(1953) # An auspicious year
n <- 200
y <- rep(0:9, length=200)
temp <- c(1,1,1,0,1,1,1,
0,0,1,0,0,1,0,
1,0,1,1,1,0,1,
1,0,1,1,0,1,1,
0,1,1,1,0,1,0,
1,1,0,1,0,1,1,
0,1,0,1,1,1,1,
1,0,1,0,0,1,0,
1,1,1,1,1,1,1,
1,1,1,1,0,1,0)

# The true light pattern 0-9
lights <- matrix(temp, 10, 7, byrow = TRUE)
# Noisy lights
temp1 <- matrix(rbinom(n*7, 1, 0.9), n, 7)
temp1 <- ifelse(lights[y+1, ] == 1, temp1, 1-temp1)
# Random lights
temp2 <- matrix(rbinom(n*17, 1, 0.5), n, 17)
x <- cbind(temp1, temp2)
``````

Share :

Generating a set random list of integers based on a distribution

By : Agus Fernandez
Date : March 29 2020, 07:55 AM
like below fixes the issue This generates all the possible combinations that sum to 10 and selects a random one
code :
``````from itertools import product
from random import choice
n=10
m=5
finalList = choice([x for x in product(*[range(2*n/m+1)]*m) if sum(x) == 10])
``````
``````finalList = choice([x for x in product(*[range(5)]*5) if sum(x) == 10])
``````
``````finalList = choice([x for x in product(range(5),range(5),range(5),range(5),range(5)) if sum(x) == 10])
``````

Generating a random number based off normal distribution in matlab

By : Kamran Chohan
Date : March 29 2020, 07:55 AM
I hope this helps you . You can use the built-in randn function which yields random numbers pulled from a standard normal distribution with a zero mean and a standard deviation of 1. To alter this distribution, you can multiply the output of randn by your desired standard deviation and then add your desired mean.
code :
``````% Define the distribution that you'd like to get
mu = 2.5;
sigma = 2.0;

% You can any size matrix of values
sz = [10000 1];

value = (randn(sz) * sigma) + mu;

%   mean(value)
%       2.4696
%
%   std(value)
%       1.9939
``````
``````value = (randn * sigma) + mu;
``````

Monte Carlo Simulation (Triangular Distribution) across rows of CSV cost data

Date : March 29 2020, 07:55 AM
it should still fix some issue Rather then doing it directly from the CSV you're better off reading the CSV into a matrix, creating your total cost matrix, and then running the for loop to simulate the values.
For example in this way:
code :
``````runs<-1000 #Set number of runs
Total_cost_items<-matrix(,nrow=runs,ncol=length(Info_costs\$Item)) #Create an empty matrix to contain your simulations
for (i in 1:length(Info_costs\$Item))
{Total_cost_items[,i]<-rtriangle(n=runs,Info_costs\$l[i],Info_costs\$u[i],Info_costs\$c[i]) }
#Fill the matrix
Total_cost_items<-data.frame(Total_cost_items, rowSums(Total_cost_items)) #append the matrix with the row sums
``````

simulation of normal distribution data contaiminated with outliers

By : Nasga
Date : March 29 2020, 07:55 AM
hop of those help? I need to simulate 1000 sets of normal distribution(each 60 subgroups, n=5) by using r programming. Each set of normal distribution is contaiminated with 4 outliers(more than 1.5 IQR). can anyone help? , A very simple approach to create a data.frame with a few outliers :
code :
``````# Create a vector with normally distributed values and a few outliers
# N - Number of random values
# n.out - number of outliers
my.rnorm <- function(N, num.out, mean=0, sd=1){
x <- rnorm(N, mean = mean, sd = sd)
ind <- sample(1:N, num.out, replace=FALSE )
x[ind] <- (abs(x[ind]) + 3*sd) * sign(x[ind])
x
}

N=60
num.out = 4
df <- data.frame( col1 = my.rnorm(N, num.out),
col2 = my.rnorm(N, num.out),
col3 = my.rnorm(N, num.out),
col4 = my.rnorm(N, num.out),
col5 = my.rnorm(N, num.out))
``````

Generating synthetic data with Gaussian distribution

By : xDeveloper
Date : March 29 2020, 07:55 AM
To fix this issue You have cut off the data at +/- 0.1. A normalised Gausian distribution only 'looks Gaussian' if you look over the range approximately +/- 3. Try this:
code :
``````import numpy as np

def generate_gaussian(size=1000, lb=-3, up=3):
data = np.random.randn(5000)
data = data[(data <= up) & (data >= lb)][:size]
return data

np.random.seed(1234)
base = generate_gaussian()
background_pos = base + 5
background_neg = base + 15
``````