THREE.js (with css3d): Shifting the scene's origin to a corner of the
rendering div
We all know that while using three.js to render graphics within a div, the
co-ordinates of every object attached to the scene are calculated w.r.t to
the origin, being the center of that div of course.
Now, the question: Does three.js provide a method to shift that origin to
the top left or any corner of the div, Such that the object co-ordinates
can be specified in a similar manner in css3??
Boose
Thursday, 3 October 2013
Wednesday, 2 October 2013
While Loop in [R]: syntax and keywords
While Loop in [R]: syntax and keywords
I want to implement a forward step-wise regression in R. BFP is a
BodyFatPercentage data set, and I am trying to create a regression model
to predict BODYFAT through step-wise regression. Keep getting an error
with the following code:
dataset <- BFP
alpha <- 0.95
namestarget <- 'BODYFAT'
inde <- c('AGE','WEIGHT','HEIGHT','NECK','CHEST','ABDOMEN',
'HIP','THIGH','KNEE','ANKLE','BICEPS','FOREARM','WRIST')
x <- 1
counter <- 0
indiLeft <- as.data.frame(subset(dataset)[inde])
fmla_sub <- NULL
fmla_sup <- NULL
while (TRUE){
print c('starting',counter,newx, indiLeft)
correlations <- cor(dataset[target],indiLeft)
newx <- colnames(correlations)[(which(correlations ==
max(correlations)))]
fmla_sub <- as.formula(paste(target,"~", paste(x, collapse= "+")))
fmla_sup <- as.formula(paste(target,"~", paste(c(x,newx), collapse=
"+")))
p <- anova(lm(fmla_sub,data=dataset),lm(fmla_sup,data=dataset),
test="F")['Pr(>F)']
if (p[2,1] < alpha){
x<- c(x,newx)
indiLeft <- indiLeft[-which(names(indiLeft) == newx)]
counter <- counter +1
next
}
else{
print ('while broken')
print (fmla_sub)
break
}
}
Can anyone figure out why this while loop only attempts the loop once?
I want to implement a forward step-wise regression in R. BFP is a
BodyFatPercentage data set, and I am trying to create a regression model
to predict BODYFAT through step-wise regression. Keep getting an error
with the following code:
dataset <- BFP
alpha <- 0.95
namestarget <- 'BODYFAT'
inde <- c('AGE','WEIGHT','HEIGHT','NECK','CHEST','ABDOMEN',
'HIP','THIGH','KNEE','ANKLE','BICEPS','FOREARM','WRIST')
x <- 1
counter <- 0
indiLeft <- as.data.frame(subset(dataset)[inde])
fmla_sub <- NULL
fmla_sup <- NULL
while (TRUE){
print c('starting',counter,newx, indiLeft)
correlations <- cor(dataset[target],indiLeft)
newx <- colnames(correlations)[(which(correlations ==
max(correlations)))]
fmla_sub <- as.formula(paste(target,"~", paste(x, collapse= "+")))
fmla_sup <- as.formula(paste(target,"~", paste(c(x,newx), collapse=
"+")))
p <- anova(lm(fmla_sub,data=dataset),lm(fmla_sup,data=dataset),
test="F")['Pr(>F)']
if (p[2,1] < alpha){
x<- c(x,newx)
indiLeft <- indiLeft[-which(names(indiLeft) == newx)]
counter <- counter +1
next
}
else{
print ('while broken')
print (fmla_sub)
break
}
}
Can anyone figure out why this while loop only attempts the loop once?
Why is Android ActionBar drop down navigation using alot of RAM?
Why is Android ActionBar drop down navigation using alot of RAM?
My app is using alot of RAM (Cached background process) when I test on a
device.
I believe it is the ActionBar.
Why is the ActionBar drop down navigation using alot of RAM?
What is wrong with the following code?
And is it wrong to navigate between activities rather than fragments?
public class CreateWorkout extends ActionBarActivity implements
ActionBar.OnNavigationListener {
String[] dropDownValues = {"GYM WORKOUT", "MENU", "CREATE WORKOUT", "LOAD
WORKOUT", "TIMER"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_workout);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(actionBar.getThemedContext(),
android.R.layout.simple_spinner_dropdown_item, dropDownValues);
actionBar.setListNavigationCallbacks(adapter, this);
}
@Override
public boolean onNavigationItemSelected(int position, long arg1) {
switch(position){
case 0:
break;
case 1:
startActivity(new Intent(CreateWorkout.this, MainActivity.class));
break;
case 2:
startActivity(new Intent(CreateWorkout.this, CreateWorkout.class));
break;
case 3:
startActivity(new Intent(CreateWorkout.this, LoadWorkout.class));
break;
case 4:
startActivity(new Intent(CreateWorkout.this, WorkoutTimer.class));
break;
}
return false;
}
}
My app is using alot of RAM (Cached background process) when I test on a
device.
I believe it is the ActionBar.
Why is the ActionBar drop down navigation using alot of RAM?
What is wrong with the following code?
And is it wrong to navigate between activities rather than fragments?
public class CreateWorkout extends ActionBarActivity implements
ActionBar.OnNavigationListener {
String[] dropDownValues = {"GYM WORKOUT", "MENU", "CREATE WORKOUT", "LOAD
WORKOUT", "TIMER"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_workout);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(actionBar.getThemedContext(),
android.R.layout.simple_spinner_dropdown_item, dropDownValues);
actionBar.setListNavigationCallbacks(adapter, this);
}
@Override
public boolean onNavigationItemSelected(int position, long arg1) {
switch(position){
case 0:
break;
case 1:
startActivity(new Intent(CreateWorkout.this, MainActivity.class));
break;
case 2:
startActivity(new Intent(CreateWorkout.this, CreateWorkout.class));
break;
case 3:
startActivity(new Intent(CreateWorkout.this, LoadWorkout.class));
break;
case 4:
startActivity(new Intent(CreateWorkout.this, WorkoutTimer.class));
break;
}
return false;
}
}
Equalitycomparer GetHashCode
Equalitycomparer GetHashCode
In this MSDN article http://msdn.microsoft.com/en-us/library/ms132123.aspx
it discusses the Class Equalitycomparer and has an example.In this example
about comparing boxes it has this class -
class BoxSameDimensions : EqualityComparer<Box>
{
public override bool Equals(Box b1, Box b2)
{
if (b1.Height == b2.Height & b1.Length == b2.Length
& b1.Width == b2.Width)
{
return true;
}
else
{
return false;
}
}
public override int GetHashCode(Box bx)
{
int hCode = bx.Height ^ bx.Length ^ bx.Width;
return hCode.GetHashCode();
}
}
I don't understand the line int hCode = bx.Height ^ bx.Length ^ bx.Width;
Could someone explain please? Why the xor?
In this MSDN article http://msdn.microsoft.com/en-us/library/ms132123.aspx
it discusses the Class Equalitycomparer and has an example.In this example
about comparing boxes it has this class -
class BoxSameDimensions : EqualityComparer<Box>
{
public override bool Equals(Box b1, Box b2)
{
if (b1.Height == b2.Height & b1.Length == b2.Length
& b1.Width == b2.Width)
{
return true;
}
else
{
return false;
}
}
public override int GetHashCode(Box bx)
{
int hCode = bx.Height ^ bx.Length ^ bx.Width;
return hCode.GetHashCode();
}
}
I don't understand the line int hCode = bx.Height ^ bx.Length ^ bx.Width;
Could someone explain please? Why the xor?
How to use REGEXP in MySQL to aquire specific columns
How to use REGEXP in MySQL to aquire specific columns
Recently i tried without successes ask MySQL DB for specific data:
SELECT code, txt_gb, txt_de FROM table WHERE code REGEXP 'chol'OR txt_gb
REGEXP 'chol' OR txt_de REGEXP 'chol' ORDER BY code COLLATE
utf8_unicode_ci
My goal is to acquire every row in which specific columns containts 'chol'
substring. I need as you see only some colums (there are more int this
table). I recieve whole table. Or maybe not whole but on first look there
are too many rows.
I created this query in JavaSE, but i don't see a reason why shoud it
interfere with asking DB.
Another thing.
I read somwhere, LIKE command has better performance that REGEXP. Is it
true? Can i use in this case LIKE instead of REGEXP to find part of cell?
I am very interesting in small load of DB.
Regards.
Recently i tried without successes ask MySQL DB for specific data:
SELECT code, txt_gb, txt_de FROM table WHERE code REGEXP 'chol'OR txt_gb
REGEXP 'chol' OR txt_de REGEXP 'chol' ORDER BY code COLLATE
utf8_unicode_ci
My goal is to acquire every row in which specific columns containts 'chol'
substring. I need as you see only some colums (there are more int this
table). I recieve whole table. Or maybe not whole but on first look there
are too many rows.
I created this query in JavaSE, but i don't see a reason why shoud it
interfere with asking DB.
Another thing.
I read somwhere, LIKE command has better performance that REGEXP. Is it
true? Can i use in this case LIKE instead of REGEXP to find part of cell?
I am very interesting in small load of DB.
Regards.
Tuesday, 1 October 2013
Sorting a string in mips?
Sorting a string in mips?
I am trying to sort a string that is entered by the user. Is there any way
to access a specific element of that string? Here is my mips code:
.data prompt: .asciiz "\n\nEnter an string of characters: " result:
.asciiz "\n\nHere is the string you entered: " buffer: .space 20 .text
main: li $v0, 4 #code for printing a string la $a0, prompt syscall
li $v0, 8 #code for reading a string la $a0, buffer li $a1, 80 syscall
li $v0, 4 #code for printing a string la $a0, result syscall
la $a0, buffer #code for printing a string li $v0, 4 syscall
I am trying to sort a string that is entered by the user. Is there any way
to access a specific element of that string? Here is my mips code:
.data prompt: .asciiz "\n\nEnter an string of characters: " result:
.asciiz "\n\nHere is the string you entered: " buffer: .space 20 .text
main: li $v0, 4 #code for printing a string la $a0, prompt syscall
li $v0, 8 #code for reading a string la $a0, buffer li $a1, 80 syscall
li $v0, 4 #code for printing a string la $a0, result syscall
la $a0, buffer #code for printing a string li $v0, 4 syscall
A Text Table Writer/Printer for Python
A Text Table Writer/Printer for Python
TL;DR -> Is there a table writing module on PyPi (I've failed to find any)
that takes in lists as parameters and makes a table out of those lists. I
am asking this because I've looked on PyPI, but I have not found anything
similar to actually printing strings or writing strings to files.
Imagine having a lot of statistics, and having to write them down neatly
in a table, like this, (I've been trying to teach a class about the
differences between the different sorting algorithms out there) (Also,
please note that the example given here does not match the output of the
code given below. I've simple done this in order to explain what I want
and not make huge chunks of code that one has to scroll through):
#########################
# LENGTH ||| TIME(s) #
#########################
# 0 ||| 0.00000 #
# 250 ||| 0.00600 #
# 500 ||| 0.02100 #
# 750 ||| 0.04999 #
# 1000 ||| 0.08699 #
# 1250 ||| 0.13499 #
# 1500 ||| 0.19599 #
# 1750 ||| 0.26900 #
# 2000 ||| 0.35099 #
#########################
Ideally, I would write something like this to save to a file, like the one
below. set of lists, one list containing the one set of values, the other
containing another set of corresponding values.
if __name__ == '__main__':
with open(os.path.join(os.path.dirname(__file__), 'Sort Stats',
'stats_exp.txt'), 'w') as stats:
stats.write(
"O-######################==#######################==#######################==######################-O\n")
stats.writelines(
"|{0:^23}||{1:^23}||{2:^23}||{3:^23}|\n".format("Bubble Sort",
"Insertion Sort", "Merge Sort (R)",
"Merge Sort
(I)"))
stats.write(
"|#######################||#######################||#######################||#######################|\n")
stats.write(
"| LENGTH | TIME(s) || LENGTH | TIME(s) || LENGTH
| TIME(s) || LENGTH | TIME(s) |\n")
stats.write(
"|#######################||#######################||#######################||#######################|\n")
for times_taken, t1, t2, t3, t4 in zip(total_lengths,
sort_times_bubble, sort_times_ins, sort_times_merge_r,
sort_times_merge_i):
stats.write(
"|{0:^11}|{1:^11}||{2:^11}|{3:^11}||{4:^11}|{5:^11}||{6:^11}|{7:^11}|\n"
.format(
times_taken, str(t1)[:6],
times_taken, str(t2)[:6],
times_taken, str(t3)[:6],
times_taken, str(t4)[:6],
)
)
stats.write(
"O-######################==#######################==#######################==######################-O\n")
print "Data writing complete"
As you can see, its not exactly pretty, and most importantly its not
something that is easy to extend, since it pretty much prints something
out.
What I want to do is create a module for this and upload it to PyPI.
However, if someone's already made something akin to this, then it would
be wasted effort, and I could simple fork their repositories instead of
actually having to write the code from scratch.
TL;DR -> Is there a table writing module on PyPi (I've failed to find any)
that takes in lists as parameters and makes a table out of those lists. I
am asking this because I've looked on PyPI, but I have not found anything
similar to actually printing strings or writing strings to files.
Imagine having a lot of statistics, and having to write them down neatly
in a table, like this, (I've been trying to teach a class about the
differences between the different sorting algorithms out there) (Also,
please note that the example given here does not match the output of the
code given below. I've simple done this in order to explain what I want
and not make huge chunks of code that one has to scroll through):
#########################
# LENGTH ||| TIME(s) #
#########################
# 0 ||| 0.00000 #
# 250 ||| 0.00600 #
# 500 ||| 0.02100 #
# 750 ||| 0.04999 #
# 1000 ||| 0.08699 #
# 1250 ||| 0.13499 #
# 1500 ||| 0.19599 #
# 1750 ||| 0.26900 #
# 2000 ||| 0.35099 #
#########################
Ideally, I would write something like this to save to a file, like the one
below. set of lists, one list containing the one set of values, the other
containing another set of corresponding values.
if __name__ == '__main__':
with open(os.path.join(os.path.dirname(__file__), 'Sort Stats',
'stats_exp.txt'), 'w') as stats:
stats.write(
"O-######################==#######################==#######################==######################-O\n")
stats.writelines(
"|{0:^23}||{1:^23}||{2:^23}||{3:^23}|\n".format("Bubble Sort",
"Insertion Sort", "Merge Sort (R)",
"Merge Sort
(I)"))
stats.write(
"|#######################||#######################||#######################||#######################|\n")
stats.write(
"| LENGTH | TIME(s) || LENGTH | TIME(s) || LENGTH
| TIME(s) || LENGTH | TIME(s) |\n")
stats.write(
"|#######################||#######################||#######################||#######################|\n")
for times_taken, t1, t2, t3, t4 in zip(total_lengths,
sort_times_bubble, sort_times_ins, sort_times_merge_r,
sort_times_merge_i):
stats.write(
"|{0:^11}|{1:^11}||{2:^11}|{3:^11}||{4:^11}|{5:^11}||{6:^11}|{7:^11}|\n"
.format(
times_taken, str(t1)[:6],
times_taken, str(t2)[:6],
times_taken, str(t3)[:6],
times_taken, str(t4)[:6],
)
)
stats.write(
"O-######################==#######################==#######################==######################-O\n")
print "Data writing complete"
As you can see, its not exactly pretty, and most importantly its not
something that is easy to extend, since it pretty much prints something
out.
What I want to do is create a module for this and upload it to PyPI.
However, if someone's already made something akin to this, then it would
be wasted effort, and I could simple fork their repositories instead of
actually having to write the code from scratch.
Subscribe to:
Comments (Atom)