I've spent some effort working with random numbers. Not the PRNGs themselves (though I'm sure that's fascinating) but how to "massage" the random bits once you get them.
For example, assume (perhaps just for fun) that random-number generation is very expensive. To make a 50-50 random coin toss you only need to expend one random bit. But what about a 53-47 biased coin? Most code will "brutishly" use up a word's worth of random bits, but you can actually make do (and my random library does) with less than one random bit on average!
Another good exercise is to select a random point uniformly in an N-ball. (If this seems trivial, consider when N is large.)
Before you get too carried away with an alternative to rot13, note that these characters come from the UTF-16 Supplemental Planes. Let's make sure the TFT rendering works:
𐎀 𐎁 𐎂 𐎃 𐎄 𐎅 𐎆 𐎇
𐎈 𐎉 𐎊 𐎋 𐎌 𐎍 𐎎 𐎏
𐎐 𐎑 𐎒 𐎓 𐎔 𐎕 𐎖 𐎗
𐎘 𐎙 𐎚 𐎛 𐎜 𐎝 𐎟
Looks OK on Preview.
RMS Value Of A Signal
RMS Root Mean Squared. In statistics it is the standard deviation, same calculation.
RSS Root Sum Squared. RMS values add by RSS.
RMS represents the energy in a signal. Equal RMS means equal thermal equivalent.
You put me on the path to something that helped me at work, with this!!Ordinary Linear Regression
In my posts, I try to achieve a balance between rigor and a simple intuitive presentation.
For this post I sacrifice rigor, and just try to outline why linear regression is elegant!
RMS Value Of A Signal
RMS Root Mean Squared. In statistics it is the standard deviation, same calculation.
RSS Root Sum Squared. RMS values add by RSS.
RMS represents the energy in a signal. Equal RMS means equal thermal equivalent.
There are many applications where RMS simply provides the correct answer to a problem. No substitutions permitted. But what about as an arbitrary measure of disparity?
When the number of points is fixed, and monotonic transfers are irrelevant, TSE (total squared error) is equivalent to RMSE and may be slightly more convenient to work with.
TSE = Σ (ypredict - yactual)2
But what about arbitrary measures of disparity? Instead of TSE, some analysrs prefer Total Absolute Error
TAE = Σ |ypredict - yactual|
or why not allow more flexibility and allow an analyst to pick whatever exponent β seems to work best in his application?
TXE = Σ |ypredict - yactual|β
But there is a lovely reason why the default exponent for measuring the efficacy of a linear prediction filter is β=2, the Total Squared Error.
The following outline of Ordinary Linear Regression is incomplete, but may still depict the underlying mathematical elegance!
We are given a "training set" of tuples (xa,1, xa,2, xa,3, ... xa,N) and the associated targets ya. The goal is to find an "optimal filter" whose dot-product with an input tuple best approximates the target value inferred from the training set.
The following is VERY sloppy. In particular, some of the A's should be AT. (Nonsense! The way A is defined, A = AT.) Corrections welcome.
Let A be the NxN matrix containing the sums Σ (xa,i·xa,j) of each (i,j) pair of coordinates across the training set.
Let F be the parameters we seek, i.e. the "filter" whose dot-product with a datum best predicts the target value.
Let T be the Nx1 vector containing the sums Σ (xa,i·ya) across the training set.
So (A·F - T) gives a form of the signed difference sum between predicted and actual targets. Square that to get the Total Squared Error!
TSE = (A·F - T)2 = (A·F)2 - 2A·F·T + T2
Let's find the F which minimizes Total Squared Error. Pretending that A, F, T are ordinary real variables instead of vectors or matrixes we expect the minimum when
d((A·F)2 - 2A·F·T + T2) / dF = 0
If we differentiate in the naive way, this becomes 2A·A·F - 2A·T = 0 or simply A·F = T.
To solve A·F = T for F, we just invert the matrix A and multiply by A-1 to get A-1·A·F = A-1·T, or simply
F = A-1·T
Presto! We've found the optimal prediction filter F !! But this only worked because differentiating a square is so simple. This is a major reason why the TSE (or RMSE) is such a popular measure of disparity! It leads to the trivial solution called Ordinary Linear Regression.
Like the drunkard looking for his keys under the lamppost because the "light is better here" even though he lost the keys on the opposite side of the street, analysts will often use TSE (equiv. RMSE) as their disparity measure even knowing some other β might be better. Zip through the training data, invert a matrix and ... after one multiply, You've found the optimal linear predictor!
const int string_null_error = 1;
const int no_error = 0;
int hex_string(char *s, unsigned int x){
if(s[4] != NULL)return(string_null_error);
char hex[16]=
{'0','1','2','3','4','5','6',
'7','8','9','a','b','c','d','e','f'};
unsigned int y = 0, mask = 0xf000;
int i = 0;
for (i = 0;i < 4;i++){
y = x & mask;
s[i] = hex[y];
mask >>= 4;
}//for
return(no_error);
}//hex_straing()
int bin_string(char *s, unsigned int x){
if(s[16] != NULL)return(string_null_error);
unsigned int mask = 0x8000;
int i = 0;
for (i = 0;i< 16;i++){
if(x & mask) s[i] = '1';
else s[i] = '0';
mask >>= 1;
}//for
return(no_error);
}//bin_string()
int main(){
unsigned int y = 0x000a;
int error = 0;
char hex_str[5], bin_str[17];
hex_str[4] = NULL;
bin_str[16] = NULL;
error = hex_string(hex_str, y);
printf("hex string 0X%s\n",hex_str);
if(error)printf(" DANGER Will Robinson!!! Unterminated String\n");
error = bin_string(bin_str, y);
printf("bin string %s\n",bin_str);
if(error)printf("Scotty I need that string terminated NOW!!!\n");
return(0);
}main()
int hex_string(char *s, unsigned int x){
if(s[4] != NULL)return(string_null_error);
char hex[16] ={'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f'};
unsigned int y = 0, mask = 0x000f;
int i = 0;
for (i = 0;i < 4;i++){
y = x & mask;
s[3-i] = hex[y];
x >>= 4;
}//for
return(no_error);
}//hex_straing()
const int FOREVER = 1;
int main()
{
double steady_state = 1e-10, p = 1,x = 1, sum_now = 0,sum_last = 0;
double perc_change = 100, limit = pow(2,32);
while(FOREVER){
sum_now += 1/pow(x,p);
x++;
//avoid /0 on start up
if(x > 1)perc_change =100*(sum_now - sum_last)/sum_last;
if(perc_change < steady_state){printf("steady state\n");break;}
if( x > limit){printf("limit\n");break;}
sum_last = sum_now;
}
printf("x %f P %f Sum %f\n", x, p, sum_now);
printf("pc %1.10f ss %1.10f\n",perc_change,steady_state);
return 0;
}
const int TRUE = 1;
int nx = 0, ny = 0, i = 0, j = 0, hit = 0;
double xmax = 10, xres = .01;
double ymax = 10, yres = .01;
double a = 0, b = 0, c = 0;
double atarget = 7, _atol = .5,ahi = 0,alo = 0;
double btarget = 4, _btol = .5,bhi = 0,blo = 0;
int main()
{
nx = ceil(xmax/xres); ny = ceil(ymax/yres);
double *x = new double[nx];
double *y = new double[ny];
ahi = atarget + _atol; alo = atarget - _atol;
bhi = btarget + _btol; blo = btarget - _btol;
for(i = 0;i<nx;i++)x[i] = i * xres;
for(i = 0;i<ny;i++)y[i] = i * yres;
for(i = 0; i < nx; i++){
for(j = 0; j < ny; j++){
a = 2*x[i] + y[j];
b = x[i] + y[j];
if(a<ahi && a>alo && b<bhi && b>blo){
hit = TRUE;
break;
}//if
}//j
if(hit)break;
}//i
if(hit){
printf("a %f b %f\n",a,b);
printf("x %f y %f\n",x[i],y[j]);
}//if
else printf("MISS\n");
return 0;
}
//main()
float fixpt2dec(unsigned int num, int nint, int nfrac){
//converts fixed point to decimal for dsplay
// sign bit 1 is negative
int i;
unsigned int mask = 1;
float fraclsb, decval = 0;
fraclsb = 1 / pow(2, nfrac);
//fractional sum
for (i = 0; i < nfrac ; i++) {
if (mask & num) decval += (fraclsb * pow(2, i));
mask = mask << 1;
}
//integer sum
for (i = 0; i<nint;i++){
if (mask & num) decval += pow(2, i);
mask = mask << 1;
}
if(num&mask)decval = decval * -1.;
return(decval);
}//fixp2dec()
int main()
{
double decval = 0;
int Nbits = 16, Nfrac = 8, Nint = 7;
unsigned int a = 0x7f00, b = 0x0100;
unsigned int acc = 0,mask = 1;
double dv1 = 0,dv2 = 0;
int nbits = 15,i;
// multiply shift and add
for (i = 0; i < nbits; i++)if (a & (mask << i)) acc += (b << i);
acc = acc >>8; // set decimal point
// decimal values for display
dv1 = fixpt2dec(a, Nint, Nfrac);
dv2 = fixpt2dec(b, Nint, Nfrac);
printf("a %3.10f b %3.10f\n",dv1,dv2);
// decimal value of multiplication product
decval = fixpt2dec(acc, Nint, Nfrac);
printf("acc 0X%x\n",acc);
printf("decval %4.8f\n",decval); ;
return(0);
}
A barrel shifter is a digital circuit that can shift a data word by a specified number of bits without the use of any sequential logic, only pure combinational logic, i.e. it inherently provides a binary operation. It can however in theory also be used to implement unary operations, such as logical shift left, in cases where limited by a fixed amount (e.g. for address generation unit). One way to implement a barrel shifter is as a sequence of multiplexers where the output of one multiplexer is connected to the input of the next multiplexer in a way that depends on the shift distance. A barrel shifter is often used to shift and rotate n-bits in modern microprocessors,[citation needed] typically within a single clock cycle.
For example, take a four-bit barrel shifter, with inputs A, B, C and D. The shifter can cycle the order of the bits ABCD as DABC, CDAB, or BCDA; in this case, no bits are lost. That is, it can shift all of the outputs up to three positions to the right (and thus make any cyclic combination of A, B, C and D). The barrel shifter has a variety of applications, including being a useful component in microprocessors (alongside the ALU).
A common usage of a barrel shifter is in the hardware implementation of floating-point arithmetic. For a floating-point add or subtract operation, the significands of the two numbers must be aligned, which requires shifting the smaller number to the right, increasing its exponent, until it matches the exponent of the larger number. This is done by subtracting the exponents and using the barrel shifter to shift the smaller number to the right by the difference, in one cycle.
Yeah, I've experience in using markup models to drive GUIs out: XAML and the likeDoes anyone here have any experience with GUI programming?
This includes the halfway GUI's of text-mode terminals like the VT100 and their emulators in many full-GUI systems.
I only did a tiny bit: using its escape codes to produce twice-size text - one for the upper half and one for the lower half.
But for full GUI's, it's a long list:
- MacOS Classic
- MacOS Cocoa - updated NeXTStep
- Windows - using Borland's app framework long ago
- Java AWT
- Python/TK - tkinter
- Android
- HTML / CSS / JavaScript