Numeral.JS zeroFormat includes $ and % symbol at end result - numeral.js

Why does zero formatting include $ and % symbols in the formatted result?
numeral.js version is 1.5.3
var number = numeral(0);
numeral.zeroFormat('N/A');
var zero = number.format('0.0%')
// 'N/A%'
var zero = number.format('$0.0')
// '$N/A'
// What I expect is 'N/A'
Is it a bug or am I missing something?
Problem duplication - https://jsfiddle.net/wbuu53qr/

Quickly found the solution. This problem happens in the older version.
Just have to move to the latest version:
var number = numeral(0);
numeral.zeroFormat('N/A');
var zero = number.format('0.0%')
// 'N/A'
https://jsfiddle.net/4jz4vp5h/

Related

Confusion Matrix - ValueError: Found input variables with inconsistent numbers of samples - how to fix?

I am getting error mentioned in the title and didn't find yet a solution.
X = train[feats].values
y = train['Target'].values
cv = StratifiedKFold(n_splits=3, random_state=2021, shuffle=True)
model = LogisticRegression(solver='liblinear')
scores = []
for train_idx, test_idx in cv.split(X, y):
model.fit(X[train_idx], y[train_idx])
y_pred = model.predict(X[test_idx])
score = mean_absolute_error(y[test_idx], y_pred )
scores.append(score)
print(np.mean(scores), np.std(scores))
fig = plt.figure(figsize=(15,6));
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)
skplt.metrics.plot_confusion_matrix(y, y_pred, ax = ax1) #error line
skplt.metrics.plot_roc(y, y_pred, ax = ax2)
ValueError: Found input variables with inconsistent numbers of samples: [32561, 10853]
I checked the code, read many threads on this error. Somebody suggested me as a solution to put the cross-validation in a loop, but I don't know how to manage this with code (and also which part of operation to put in a loop, and how to write a condition that should be ending this loop). Please, help me with a specific answer that will help me to easily fix problem with my current level of advancement.

Context Free Grammar for English Sounding Names

I am currently writing an application that will generate random data; specifically, random names. I have made some decent progress, but am not satisfied with many of the generated names. The problem lies in my production rules, which I've attached to the bottom of this post.
The basic idea is: consonant, vowel, consonant, vowel, but some consonants themselves map to vowels (such as b< VO >).
I have not fully created the rules yet, but the final idea would follow the format shown below. However, rather than finishing it, I would like to make a better basis for the production rules.
I have tried to find a reference that discusses either: a CFG already created for English-sounding words, or an English reference that disassembles the basic format of letter combinations for words. Unfortunately, I have not been able to find a useful resource to help me advance farther than I already have. Does anyone know of a place I should look, or a reference I can look at?
ALSO: in your opinion, do you believe a context-sensitive grammar might work better?
//the following will deal with single vowels and consonants
var CO = ['b','c','d','f','g','h','j','k','l','m','n','p','qu','r','s','t','v','w','x','y','z'];
CO.probabilities = [2.41,4.49,6.87,3.59,3.25,9.84,0.24,1.24,6.5,3.88,10.9,3.11,0.153,9.67,10.2,14.6,1.58,3.81,0.242,3.19,0.12];
CO.name = "CO";
var VO = ['a','e','i','o','u'];
VO.probabilities = [21.43,33.33,18.28,19.7,7.23];
VO.name = "VO";
var LETTER = ['<VO>','<CO>'];
LETTER.probabilities = [38.1,61.9];
LETTER.name = "LETTER";
//the following deal with connsonant pairs
var BH = ['c','p','r','s','t']; //the fisrt part of a th, ph, sh, pair (before H)
BH.probabilities = [20,10,20,25,25];
BH.name = "BH";
var BL = ['b','c','f','g','p','s']; //before letter l
BL.probabilities = [10,20,10,10,25,25]
BL.name = "BL";
var COP = ['<BH>h','<BL>l'] //consonant pairs
COP.probabilities = [50,50];
COP.name = "COP";
//this is a generic syllable, that does not take grammar rules into consideration
var SYL = ['<CO><VO>','<VO><CO>','<CO><VO><VO>'];
SYL.probabilities = [50,20,30];
SYL.name = "SYL";
//the following deal with mid word syllablse
var CLOSED = ['<CO><VO><CO>','<CO><VO><CO><CO>'];
CLOSED.probabilities = [75,25];
CLOSED.name = "CLOSED";
var OPEN = ['<CO><VO>','<CO><CO><VO>'];
OPEN.probabilities = [60,40];
OPEN.name = "OPEN";
var VR = ['<VO>r']; //vowel-r
VR.probabilities = [100];
VR.name = "VR";
var MID = ['<CLOSED>','<OPEN>','<VR>'];
MID.probabilities = [33,33,33];
MID.name = "MID";
//the following will deal with ending syllables
var VCE = ['<VO><CO>e','<LETTER><VO><CO>e'];
VCE.probabilities = [75,25];
VCE.name = "VCE";
var CLE = ['<CO>le'];
CLE.probabilities = [100];
CLE.name = "CLE";
var OE = ['tion','age','ive']; //other endings
OE.probabilities = [33,33,33];
OE.name = "OE";
var ES = ['<VCE>','<CLE>','<OE>','<VR>']; //contains all ending syllables
ES.probabilities = [40,40,20];
ES.name = "ES";
var rules = [CO,VO,BH,BL,COP,LETTER,SYL,CLOSED,OPEN,VR,MID,VCE,CLE,OE,ES];
//These are some highly-defined production rules
var streetSuffix = ['road','street','way','avenue','drive','grove','lane','gardens','place','crescent','close','square','hill','circus','mews','vale','rise','mead'];
streetSuffix.probabilities = [15,15,5,10,5,2.7,2.7,2.7,2.7,2.7,2.7,2.7,2.7,2.7,2.7,2.7,2.7,2.7];
var states = ['Alabama','Alaska','American Samoa','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','Florida','Georgia','Guam','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Marshall Islands','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Palau','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virgin Island','Virginia','Washington','West Virginia','Wisconsin','Wyoming'];
var cityNewWordSuffix = ['city','town',''];
var cityEndWordSuffix = ['polis','ville','ford','furt','forth','shire','berg','gurg','borough','brough','field','kirk','bury','stadt',''];
var siteSuffix = ['com','org','net','edu'];
/**
This will generate a random name of Length length
*/
function generateRandomName() {
//string will be random length of CO VO pattern for now
var result;
result = "<COP><VO><MID><VO><ES>";
while (hasNonTerminal(result)) {
result = replaceFirstNonTerminal(result);
}
return result;
}
Here are a few words generated by the machine in its current state:
"cheiroene",
"sloeraase",
"sledehgeute",
"rhaorenone",
"rheerisute",
"chaereehe",
"sletraoege",
"sluureese",
"chaheyleete",
"chierauhe",
"ploclooate",
"glawofhaice",
"thanisgoage",
"slelaodose",
"blaereode",
"shihudeife",
"slaereene",
"pleheaele",
"rhepicsaile",
"ploeruoge",
"sliareuhe",
"thaereafe",
"thaaraeke",
"cheoreate",
"shofetniote",
"phiraoese",
"clilniueye",
"slepceikede",
"cligloueohe",
"phitleoime",

Dealing with under flow while calculating GMM parameters using EM

I am currently runnuing training in matlab on a matrix of logspecrum samples I am constantly dealing with underflow problems.I understood that I need to work with log's in order to deal with underflowing.
I am still strugling with uderflow though , when i calculate the mean (mue) bucause it is negetive i cant work with logs so i need the real values that underflow.
These are equasions i am working with:
In MATLAB code i calulate log_tau in oreder avoid underflow but when calulating mue i need exp(log(tau)) which goes to zero.
I am attaching relevent MATLAB code
**in the code i called the variable alpha is tau ...
for i = 1 : 50
log_c = Logsum(log_alpha,1) - log(N);
c = exp(log_c);
mue = DataMat*alpha./(repmat(exp(Logsum(log_alpha,1)),FrameSize,1));
log_abs_mue = log(abs(mue));
log_SigmaSqr = log((DataMat.^2)*alpha) - repmat(Logsum(log_alpha,1),FrameSize,1) - 2*log_abs_mue;
SigmaSqr = exp(log_SigmaSqr);
for j=1:N
rep_DataMat(:,:,j) = repmat(DataMat(:,j),1,M);
log_gamma(j,:) = log_c - 0.5*(FrameSize*log(2*pi)+sum(log_SigmaSqr)) + sum((rep_DataMat(:,:,j) - mue).^2./(2*SigmaSqr));
end
log_alpha = log_gamma - repmat(Logsum(log_gamma,2),1,M);
alpha = exp(log_alpha);
end
c = exp(log_c);
SigmaSqr = exp(log_SigmaSqr);
does any one see how i can avoid this? or what needs to be fixed in code?
What i did was add this line to the MATLAB code:
mue(isnan(mue))=0; %fix 0/0 problem
and this one:
SigmaSqr(SigmaSqr==0)=1;%fix if mue_k = x_k
not sure if this is the best solution but is seems to work...
any have a better idea?

Aparapi add sample

I'm studing Aparapi (https://code.google.com/p/aparapi/) and have a strange behaviour of one of the sample included.
The sample is the first, "add". Building and executing it, is ok. I also put the following code for testing if the GPU is really used
if(!kernel.getExecutionMode().equals(Kernel.EXECUTION_MODE.GPU)){
System.out.println("Kernel did not execute on the GPU!");
}
and it works fine.
But, if I try to change the size of the array from 512 to a number greater than 999 (for example 1000), I have the following output:
!!!!!!! clEnqueueNDRangeKernel() failed invalid work group size
after clEnqueueNDRangeKernel, globalSize[0] = 1000, localSize[0] = 128
Apr 18, 2013 1:31:01 PM com.amd.aparapi.KernelRunner executeOpenCL
WARNING: ### CL exec seems to have failed. Trying to revert to Java ###
JTP
Kernel did not execute on the GPU!
Here's my code:
final int size = 1000;
final float[] a = new float[size];
final float[] b = new float[size];
for (int i = 0; i < size; i++) {
a[i] = (float)(Math.random()*100);
b[i] = (float)(Math.random()*100);
}
final float[] sum = new float[size];
Kernel kernel = new Kernel(){
#Override public void run() {
int gid = getGlobalId();
sum[gid] = a[gid] + b[gid];
}
};
Range range = Range.create(size);
kernel.execute(range);
System.out.println(kernel.getExecutionMode());
if (!kernel.getExecutionMode().equals(Kernel.EXECUTION_MODE.GPU)){
System.out.println("Kernel did not execute on the GPU!");
}
kernel.dispose();
}
I tried specifying the size using
Range range = Range.create(size, 128);
as suggested in a Google group, but nothing changed.
I'm currently running on Mac OS X 10.8 with Java 1.6.0_43. Aparapi version is the latest (2012-01-23).
Am I missing something? Any ideas?
Thanks in advance
Aparapi inherits a 'Grid Style' of implementation from OpenCL. When you specify a range of execution (say 1024), OpenCL will break this 'range' into groups of equal size. Possibly 4 groups of 256, or 8 groups of 128.
The group size must be a factor of range (so assert(range%groupSize==0)).
By default Aparapi internally selects the group size.
But you are choosing to fully specify the range and group size to using
Range r= Range.range(n,128)
You are responsible for ensuring that n%128==0.
From the error, it looks like you chose Range.range(1000,128).
Sadly 1000 % 128 != 0 so this range will fail.
If you specifiy
Range r = Range.range(n)
Aparapi will choose a valid group size, by finding the highest common factor of n.
Try dropping the 128 as the the second arg.
Gary

Ruby multi-line regex

I have a ruby multi-line string (called efixes) that looks like:
ID STATE LABEL INSTALL TIME UPDATED BY ABSTRACT
=== ===== ========== ================= ========== ======================================
1 S hayo32.02 xxxxxxx xxxxxxxx xxxxxxxxxxxxxxx
2 S 23434.23 xxxxxxx xxxxxxxx xxxxxxxxxxxxxxx
STATE codes:
S = STABLE
M = MOUNTED
U = UNMOUNTED
Q = REBOOT REQUIRED
B = BROKEN
I = INSTALLING
R = REMOVING
T = TESTED
P = PATCHED
N = NOT PATCHED
SP = STABLE + PATCHED
SN = STABLE + NOT PATCHED
QP = BOOT IMAGE MODIFIED + PATCHED
QN = BOOT IMAGE MODIFIED + NOT PATCHED
RQ = REMOVING + REBOOT REQUIRED
I only want to display the lines that start with a number. I am having trouble, it doesn't seem to be matching. I found this solution here, (that I don't truly understand right now):
efixes_array = efixes.split("\n").select{|x| /\A[0-9]/.match(x)}
io.puts efixes_array.collect{|x| x.scan(/\A[0-9]/)}.flatten
It is only matching the numbers. I want to display the entire line. The end result, I want to display what is under the "LABELS" column.
This line from your example code
efixes.split("\n").select{|x| /\A[0-9]/.match(x)}
returns an array with all lines that start with a number.

Resources