The code below adds custom text to each equation using a local and produces what I want:
estimates clear
eststo clear
sysuse auto, clear
eststo w1: regress price mpg trunk length
estadd local number one
eststo w2: regress turn mpg trunk length
estadd local number two
eststo w3: regress displacement mpg trunk length
estadd local number three
esttab w1 w2 w3, stats(number)
However, I would like to be able to write the custom text in the esttab command syntax and not before using locals.
This is incorrect, but the option might look something like the following:
estimates clear
eststo clear
sysuse auto, clear
eststo w1: regress price mpg trunk length
eststo w2: regress turn mpg trunk length
eststo w3: regress displacement mpg trunk length
esttab w1 w2 w3, stats("number", "one" "two" "three")
Can I somehow insert an option to the esttab command where I spell out what I want? I know that there is an indicate() option, but I could not figure out if it can do what I need or not.
Unfortunately, you cannot define the contents of a stats() element on the fly.
However, a workaround is the following:
sysuse auto, clear
eststo clear
estimates clear
eststo w1: regress price mpg trunk length
eststo w2: regress turn mpg trunk length
eststo w3: regress displacement mpg trunk length
esttab, prefoot(`"{hline 60}"' ///
`"numbers{dup 15: }one{dup 13: }two{dup 11: }three"' ///
`"more numbers{dup 9: }four{dup 12: }five{dup 13: }six"')
------------------------------------------------------------
(1) (2) (3)
price turn displacement
------------------------------------------------------------
mpg -173.7 -0.0656 -1.777
(-1.97) (-0.88) (-1.04)
trunk -0.855 -0.0593 0.0659
(-0.01) (-0.66) (0.03)
length 21.40 0.165*** 3.068***
(0.79) (7.19) (5.83)
_cons 5854.0 10.76* -342.3**
(0.97) (2.09) (-2.92)
------------------------------------------------------------
numbers one two three
more numbers four five six
N 74 74 74
------------------------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
Obviously, you will have to specify every time the spaces according to your use case. You can do this manually or by writing a small program that calculates these.
Related
I want to make a 8 bit s-box using 4 bit s-box. So is there any easy, understandable algorithm or source to help me?
There is always an easy one, however, that is not guaranteed to carry the security.
4-bit SBox has 4-bit input and 4-bit output. So we can consider that as an array of size 16' S16[16]
8-bit SBox has 8-bit input and 8-bit output. So we can consider that as an array of size 64' S64[64]
Initially, we can copy 4 copies of S16 into S64, however, that won't be a good SBox and the inverse will be failed.
Now, we can use the extra 4-bit to modify the 2,3, and 4 copies as
# copy the 4-Box directly
for i in range(0..16):
S64[i] = S16[i]
# Add 16 the 4-Box's elements then assign
for i in range(16..32):
S64[i] = S16[i-16] *2
# Now add 32 to the first half then assign.
for i in range(32..64):
S64[i] = 32 + S64[i-32] ```
So
the 1st quarter has elements in the range [ 0,15]
the 2nd quarter has elements in the range [16,31]
the 3rd quarter has elements in the range [32,47]
the 4th quarter has elements in the range [48,64]
I want to create a mathematical model for 2d bin packing optimization problem. I am not quite sure if it is bin packing problem it may be called strip packing, anyway let me introduce the problem.
1- There are some group of boxes to be placed on strips (see article 3.)
2- Each group contains a number of boxes which have same width and same hight. For example,
group A
100 boxes with width = 80cm and height = 120cm
group B
250 boxes with width = 150cm and height = 200cm
etc.
3- There are unlimited number of equal sized strips which have fixed width and height, for example
infinite number of Width = 800cm and Height 1400cm
4- The main goal is packing these boxes into minimum number of the strips. However, there are some restrictions to do this job.
5- If we think of the strips as a 2d row and column plane, at each column must has a fixed width of boxes. For example, if (column 0 and row 0) has a box w=100,h=80 then (column 0 and row 1) also has to has a box w=100,h=80. It is not allowed to be in the same column for diferent sized boxes. This rule is not valid for rows. Each row can have different sized boxes, there is no restriction.
6- It is not important to fill the whole strip. We want to fill strips with minimum space between boxes. The heighest column indicates a stop line through other columns and we calculate the loss value (space ratio over the whole strip area).
I tried to implement this optimization problem with GLPK linear programming tool. I have used a mathematical model from the paper (C. Blum, V. Schmid Solving the 2D bin packing problem by means of a hybrid evolutionary algorithm)
C. Blum, V. Schmid Solving the 2D bin packing problem by means of a hybrid evolutionary algorithm
This math model works great in the GLPK. However, it is designed for boxes for packing in x,y coordinates. If you see article 5 we want them in a fixed-width column fashion.
Can you please help me to modify the mathematical model to make possible to implement article 5.
Thank you all,
I have the task to simulate a camera with a full well capacity of 10.000 Photons per sensor element
in numpy. My first Idea was to do it like that:
camera = np.random.normal(0.0,1/10000,np.shape(img))
Imgwithnoise= img+camera
but it hardly shows an effect.
Has someone an idea how to do it?
From what I interpret from your question, if each physical pixel of the sensor has a 10,000 photon limit, this points to the brightest a digital pixel can be on your image. Similarly, 0 incident photons make the darkest pixels of the image.
You have to create a map from the physical sensor to the digital image. For the sake of simplicity, let's say we work with a grayscale image.
Your first task is to fix the colour bit-depth of the image. That is to say, is your image an 8-bit colour image? (Which usually is the case) If so, the brightest pixel has a brightness value = 255 (= 28 - 1, for 8 bits.) The darkest pixel is always chosen to have a value 0.
So you'd have to map from the range 0 --> 10,000 (sensor) to 0 --> 255 (image). The most natural idea would be to do a linear map (i.e. every pixel of the image is obtained by the same multiplicative factor from every pixel of the sensor), but to correctly interpret (according to the human eye) the brightness produced by n incident photons, often different transfer functions are used.
A transfer function in a simplified version is just a mathematical function doing this map - logarithmic TFs are quite common.
Also, since it seems like you're generating noise, it is unwise and conceptually wrong to add camera itself to the image img. What you should do, is fix a noise threshold first - this can correspond to the maximum number of photons that can affect a pixel reading as the maximum noise value. Then you generate random numbers (according to some distribution, if so required) in the range 0 --> noise_threshold. Finally, you use the map created earlier to add this noise to the image array.
Hope this helps and is in tune with what you wish to do. Cheers!
I'm trying to design a kind of water valve with inexpensive materials as a first prototype.
The water flow from the PVC pipe (1) reach the body of the valve and pass through an aluminum grid (3) to the water tank. When the water level goes up pushes the float closing the water intake at point (2).
enter image description here
How can I calculate the buoyancy force needed to stop the water flow? And, what will be the mass of the float?
Let’s back to the basics; here I present the problem and some math that I been doing, I would like your opinion:
Connected to the PVC pipe (2) I have a garden hose whit a water flow pressure of, let's say...49 kPa (I need to check this with a manometer), and I attached a 25 diameter and 0.5 meters long PVC pipe. Let’s pretend that the float seals the other side of the PVC pipe, so I need to calculate the force generate by the water flow pressure against the float.
Please take in consideration that I'm not a fluid mechanic expert.
When I open the garden hose, the PVC pipe starts to fill, so based on this situation:
enter image description here
P1+ρgh_1+(v^1 ρ)/2=P2+ρgh_2+(v^2 ρ)/2
If I took the height of P1 as the reference, h=0, and the diameter of the PVC pipe and the garden hose pipe are the same (25 mm), the water flow velocity at those points are equals:
P1=P2+ρgh_2
So, if the garden hose pressure is 49 Kpa:
49000 kg/(m s^2 )=P2+9.8 m/(s^2 ) x 1000 kg/m^3 x 0.5 m
P2=53900 kg/(m s^2 )
P2=53.9 Kpa
Ok, assuming this math is correct…now I have to calculate the force against the bottom of the PVC pipe at point 2:
P=F/A
In order to simplify this example, I took the diameter of the PVC pipe as the contact area.
A=πr^2=π(〖0.025〗^2 )=0.002 m^2
F=107.8 N
If the pressure of the water flow generates a force of 107.8 N, I need an opposite force with a higher value to counteract it. Is that correct?
My goal is to find a material (mass; area) that generate enough buoyancy force to stop the water flow through the valve and seal the water intake, and when the water level goes down, the float valve will let pass the water flow to continue to fill the water tank.
I agree with the previous comment : the pressure at the contact is the total pressure at the line feed (corrected for gravity at height 1). When water is flowing, some of that pressure is converted to dynamic pressure, meaning you will measure a lower pressure at point 1; the total sum at p+1/2 v^2 should remain more or less the same irrespective of v - if we neglecting head losses running up to point 1 which depend on the flow rate.
Anyway, when the valve is closed, the flow is stopping anyway, so you it is even more obvious to work with the static pressure measured in the absence of flow.
You need to choose the density and form of your floater such that the buoyancy force, given by $(density of water - density of floater material)*(submerged volume at chosen reservoir height)$ is equal to $p2 * A$.
I'm trying to implement a variable exponential moving average on a time series of intraday data (i.e 10 seconds). By variable, I mean that the size of the window included in the moving average depends on another factor (i.e. volatility). I was thinking of the following:
MA(t)=alpha(t)*price(t) + (1-alpha(t))MA(t-1),
where alpha corresponds for example to a changing volatility index.
In a backtest on huge series (more than 100000) points, this computation causes me "troubles". I have the complete vectors alpha and price, but for the current values of MA I always need the value just calculated before. Thus, so far I do not see a vectorized solution????
Another idea, I had, was trying to directly apply the implemented EMA(..,n=f()) function to every data point, by always having a different value for f(). But I do not find a fast solution neither so far.
Would be very kind if somebody could help me with my problem??? Even other suggestions of how constructing a variable moving average would be great.
Thx a lot in advance
Martin
A very efficient moving average operation is also possible via filter():
## create a weight vector -- this one has equal weights, other schemes possible
weights <- rep(1/nobs, nobs)
## and apply it as a one-sided moving average calculations, see help(filter)
movavg <- as.vector(filter(somevector, weights, method="convolution", side=1))
That was left-sided only, other choices are possible.
For timeseries, see the function rollmean in the zoo package.
You actually don't calculate a moving average, but some kind of a weighted cumulative average. A (weighted) moving average would be something like :
price <- runif(100,10,1000)
alpha <- rbeta(100,1,0.5)
tp <- embed(price,2)
ta <- embed(alpha,2)
MA1 <- apply(cbind(tp,ta),1,function(x){
weighted.mean(x[1:2],w=2*x[3:4]/sum(x))
})
Make sure you rescale the weights so they sum to the amount of observations.
For your own calculation, you could try something like :
MAt <- price*alpha
ma.MAt <- matrix(rep(MAt,each=n),nrow=n)
ma.MAt[upper.tri(ma.MAt)] <- 0
tt1 <- sapply(1:n,function(x){
tmp <- rev(c(rep(0,n-x),1,cumprod(rev(alpha[1:(x-1)])))[1:n])
sum(ma.MAt[i,]*tmp)
})
This calculates the averages as linear combinations of MAt, with weights defined by the cumulative product of alpha.
On a sidenote : I assumed the index to lie somewhere between 0 and 1.
I just added a VMA function to the TTR package to do this. For example:
library(quantmod) # loads TTR
getSymbols("SPY")
SPY$absCMO <- abs(CMO(Cl(SPY),20))/100
SPY$vma <- VMA(Cl(SPY), SPY$absCMO)
chartSeries(SPY,TA="addTA(SPY$vma,on=1,col='blue')")
x <- xts(rnorm(1e6),Sys.time()-1e6:1)
y <- xts(runif(1e6),Sys.time()-1e6:1)
system.time(VMA(x,y)) # < 0.5s on a 2.2Ghz Centrino
A couple notes from the documentation:
‘VMA’ calculate a variable-length
moving average based on the absolute
value of ‘w’. Higher (lower) values
of ‘w’ will cause ‘VMA’ to react
faster (slower).
The pre-compiled binaries should be on R-forge within 24 hours.