Search Results

Search found 5192 results on 208 pages for 'random forests'.

Page 33/208 | < Previous Page | 29 30 31 32 33 34 35 36 37 38 39 40  | Next Page >

  • Random Loss of precision in Python ReadLine()

    - by jackyouldon
    Hi all, We have a process which takes a very large csv (1.6GB) and breaks it down into pieces (in this case 3). This runs nightly and normally doesn't give us any problems. When it ran last night, however, the first of the output files had lost precision on the numeric fields in the data. The active ingredient in the script are the lines: while lineCounter <= chunk: oOutFile.write(oInFile.readline()) lineCounter = lineCounter + 1 and the normal output might be something like StringField1; StringField2; StringField3; StringField4; 1000000; StringField5; 0.000054454 etc. On this one occasion and in this one output file the numeric fields were all output with 6 zeros at the end i.e. StringField1; StringField2; StringField3; StringField4; 1000000.000000; StringField5; 0.000000 We are using Python v2.6 (and don't want to upgrade unless we really have to) but we can't afford to lose this data. Does anyone have any idea why this might have happened? If the readline is doing some kind of implicit conversion is there a way to do a binary read, because we really just want this data to pass through untouched? It is very wierd to us that this only affected one of the output files generated by the same script, and when it was rerun the output was as expected. thanks Jack

    Read the article

  • 'Random' Orderby in webservice using LINQ To Entities

    - by MrDean
    Morning all Now I know there is a reason to this odering but my tiny little brain can't get my head around it. I am using a webservice to pull through data to a webp[age and have the following that is so far pulling data through from UUF1: public string[] GetBuyer(string Memberkey) { try { WebService.EntitiesConnection buyer = new WebService.EntitiesConnection(); return buyer.tblProducts .Where(p => p.MemberId == Memberkey) .OrderBy(p => p.UnitUserfield1) .Select(p => p.UnitUserfield1) .Distinct() .ToArray(); } catch (Exception) { return null; } } This works fine and pulls the data through but in a strange order. Where I would expect results of A B C D E F, it appears to be returning A C E B D F. Could someone point out the error in my ways please?

    Read the article

  • Proc causing a random TypeError

    - by go____yourself
    I'm refactoring some code and this proc is causing an error randomly and I don't know why or how to debug it... Any ideas? New code with proc defense_moves, offense_moves = [], [] determine_move = ->move,side,i { side << move.count(move[i]) } defense.size.times { |i| determine_move.(defense, defense_moves, i) } offense.size.times { |i| determine_move.(offense, offense_moves, i) } dm = defense[defense_moves.index(defense_moves.max)].nil? ? [0] : defense[defense_moves.index(defense_moves.max)] om = offense[offense_moves.index(offense_moves.max)].nil? ? [0] : offense[offense_moves.index(offense_moves.max)] Original code: d = 0 defense_moves = [] loop do defense_moves << defense.count(defense[d]) break if defense.count(defense[d]).zero? d += 1 end o = 0 offense_moves = [] loop do offense_moves << offense.count(offense[o]) break if offense.count(offense[o]).zero? o += 1 end dm = defense[defense_moves.index(defense_moves.max)].nil? ? [0] : defense[defense_moves.index(defense_moves.max)] om = offense[offense_moves.index(offense_moves.max)].nil? ? [0] : offense[offense_moves.index(offense_moves.max)] TypeError ttt2.rb:95:in `[]': no implicit conversion from nil to integer (TypeError) from ttt2.rb:95:in `computer_make_move' from ttt2.rb:133:in `draw_board' from ttt2.rb:24:in `place' from ttt2.rb:209:in `block in start_new_game' from ttt2.rb:188:in `loop' from ttt2.rb:188:in `start_new_game' from ttt2.rb:199:in `block in start_new_game' from ttt2.rb:188:in `loop' from ttt2.rb:188:in `start_new_game' from ttt2.rb:199:in `block in start_new_game' from ttt2.rb:188:in `loop' from ttt2.rb:188:in `start_new_game' from ttt2.rb:199:in `block in start_new_game' from ttt2.rb:188:in `loop' from ttt2.rb:188:in `start_new_game' from ttt2.rb:199:in `block in start_new_game' from ttt2.rb:188:in `loop' from ttt2.rb:188:in `start_new_game' from ttt2.rb:234:in `<main>'

    Read the article

  • How can I create an array of random numbers in C++

    - by Nick
    Instead of The ELEMENTS being 25 is there a way to randomly generate a large array of elements....10000, 100000, or even 1000000 elements and then use my insertion sort algorithms. I am trying to have a large array of elements and use insertion sort to put them in order and then also in reverse order. Next I used clock() in the time.h file to figure out the run time of each algorithm. I am trying to test with a large amount of numbers. #define ELEMENTS 25 void insertion_sort(int x[],int length); void insertion_sort_reverse(int x[],int length); int main() { clock_t tStart = clock(); int B[ELEMENTS]={4,2,5,6,1,3,17,14,67,45,32,66,88, 78,69,92,93,21,25,23,71,61,59,60,30}; int x; cout<<"Not Sorted: "<<endl; for(x=0;x<ELEMENTS;x++) cout<<B[x]<<endl; insertion_sort(B,ELEMENTS); cout <<"Sorted Normal: "<<endl; for(x=0;x<ELEMENTS;x++) cout<< B[x] <<endl; insertion_sort_reverse(B,ELEMENTS); cout <<"Sorted Reverse: "<<endl; for(x=0;x<ELEMENTS;x++) cout<< B[x] <<endl; double seconds = clock() / double(CLK_TCK); cout << "This program has been running for " << seconds << " seconds." << endl; system("pause"); return 0; }

    Read the article

  • generating random enums

    - by null_radix
    How do I randomly select a value for an enum type in C++? I would like to do something like this. enum my_type(A,B,C,D,E,F,G,h,J,V); my_type test(rand() % 10); But this is illegal... there is not an implicit conversion from int to an enum type.

    Read the article

  • Python: Random integer

    - by user3696440
    I been hitting a wall thats been keeping me from tinkering on a game. class Damage: def shortsword(): shortsword=randint(1,6)+1 shortsword=int(shortsword) return shortsword I been wanting this number to pop up as part of a message on print and then use the same number as part of another function to help with subtracting of health on the target. Though each time I grab this it is always going to change.

    Read the article

  • Get a random folder C# .NET

    - by Joshua
    Hi. public sealed static class FolderHelper { public static string GetRandomFolder() { // do work } } But.... How? Like start at c:\ (or whatever the main drive is) and then randomly take routes? Not even sure how to do that.

    Read the article

  • Stochastic calculus library in python

    - by LeMiz
    Hello, I am looking for a python library that would allow me to compute stochastic calculus stuff, like the (conditional) expectation of a random process I would define the diffusion. I had a look a at simpy (simpy.sourceforge.net), but it does not seem to cover my needs. This is for quick prototyping and experimentation. In java, I used with some success the (now inactive) http://martingale.berlios.de/Martingale.html library. The problem is not difficult in itself, but there is a lot non trivial, boilerplate things to do (efficient memory use, variable reduction techniques, and so on). Ideally, I would be able to write something like this (just illustrative): def my_diffusion(t, dt, past_values, world, **kwargs): W1, W2 = world.correlated_brownians_pair(correlation=kwargs['rho']) X = past_values[-1] sigma_1 = kwargs['sigma1'] sigma_2 = kwargs['sigma2'] dX = kwargs['mu'] * X * dt + sigma_1 * W1 * X * math.sqrt(dt) + sigma_2 * W2 * X * X * math.sqrt(dt) return X + dX X = RandomProcess(diffusion=my_diffusion, x0 = 1.0) print X.expectancy(T=252, dt = 1./252., N_simul= 50000, world=World(random_generator='sobol'), sigma1 = 0.3, sigma2 = 0.01, rho=-0.1) Does someone knows of something else than reimplementing it in numpy for example ?

    Read the article

  • take out objects from randomizer obj c

    - by David Pollak
    hello everyone, I'm a new "developer" trying to build some iPhone app I'm making an app which gets text from a list of objects in a NSArray and then randomizes them and display one in a TextView, here's the code: - (IBAction)azione{ NSArray *myArray= [NSArray arrayWithObjects: @"Pasta",@"Pizza",@"Wait",@"Go", nil]; int length = [myArray count]; int chosen = arc4random() % length; testo.text = [myArray objectAtIndex: chosen]; } what I want to do now, is when I open the app and get a random object, to take it out from the list, so that it won't be picked again ex. I open the appI get "Pizza"Do the action againI don't get "Pizza" anymore, only "Pasta" "Wait" and "Go" What should I do ? Which code should I use ? Thanks for answers

    Read the article

  • Simple hardware RNG

    - by roygbiv
    I made a tongue-in-cheek comment to this question about making a hardware RNG. Does anyone know of any simple plans or can anyone descibe a simple hardware based RNG and the software to drive it? Go to Radio Shack. Buy a diode, an NTR resistor, a capacitor and serial cable. Cut off the end of the serial cable that does not fit on your computer. Solder the diode and resistor in series between pins DTR and DSR of the cable. Solder the capacitor between DSR and TXD pins. Write a small C program to do the following: Set DTR to 1. Start Timer. Monitor DSR until it goes to 1. Stop Timer. Calculate resistance from elapsed time. Retreive serveral bits from that value to use as part of random number. Repeat until enough bits have accumulated.

    Read the article

  • Efficient banner rotation with PHP

    - by reggie
    I rotate a banner on my site by selecting it randomly from an array of banners. Sample code as demonstration: <?php $banners = array( '<iframe>...</iframe>', '<a href="#"><img src="#.jpg" alt="" /></a>', //and so on ); echo $banners(rand(0, count($banners))); ?> The array of banners has become quite big. I am concerned with the amount of memory that this array adds to the execution of my page. But I can't figure out a better way of showing a random banner without loading all the banners into memory...

    Read the article

  • ideas for algorithm? sorting a list randomly with emphasis on variety

    - by Steve Eisner
    I have a table of items with [ID,ATTR1,ATTR2,ATTR3]. I'd like to select about half of the items, but try to get a random result set that is NOT clustered. In other words, there's a fairly even spread of ATTR1 values, ATTR2 values, and ATTR3 values. This does NOT necessarily represent the data as a whole, in other words, the total table may be generally concentrated on certain attribute values, but I'd like to select a subset with more variety. The attributes are not inter-related, so there's not really a correlation between ATTR1 and ATTR2. Any ideas for an efficient algorithm? Thanks! I don't really even know how to search for this :)

    Read the article

  • How to always return a set number of records when using find_related_tags with acts-as-taggable-on

    - by hadees
    I'm using the acts-as-taggable-on gem and I need to use find_related_tags on my survey model to get back 3 surveys every time. In the event there aren't always 3 related I need to pick how ever many are related plus some random ones to get to 3. Additionally I have a method I wrote called completed_survey_ids which return an array of survey_ids that shouldn't be used because the user has already completed them. Also there is a rare case that there won't be enough surveys because the user has completed them all so in that event it is okay to return less surveys then requested. I did write a named_scope to handle getting rid of the completed_survey_ids that I think works named_scope :not, lambda { |survey_ids| {:conditions => "id NOT IN (#{survey_ids.join(',')})" } }

    Read the article

  • Most efficient way to randomly "sort" (Shuffle) a list of integers in C#

    - by Carl
    I need to randomly 'sort' a list of integers (0-1999) in the most efficient way possible. Any ideas? Currently, I am doing something like this: bool[] bIndexSet = new bool[iItemCount]; for (int iCurIndex = 0; iCurIndex < iItemCount; iCurIndex++) { int iSwapIndex = random.Next(iItemCount); if (!bIndexSet[iSwapIndex] && iSwapIndex != iCurIndex) { int iTemp = values[iSwapIndex]; values[iSwapIndex] = values[iCurIndex]; values[iCurIndex] = values[iSwapIndex]; bIndexSet[iCurIndex] = true; bIndexSet[iSwapIndex] = true; } }

    Read the article

  • Randomize numbers within a subset

    - by Samuel
    I have a array of integer numbers (say 1,2,3,4,5 or 1,2,3, ... 10 or 1,2,3, ... 50) from which I would like to get a random set of numbers ordered differently every time. Is there a utility method to do this? e.g. for 1,2,3,4,5 post randomization it might be either [1,5,4,2,3 or 2,1,3,5,4 or 3,1,2,4,5 or ...] I would like to know if there is a java utility method / class which already provides this capability?

    Read the article

  • jQuery: how to pick unique IDs ?

    - by Seerumi
    Hello. New to whole this jQuery (and javascript altogether, heh) and so far it's been excellent, but now I'm in a small pickle. Let's say I have list of forms generated from SQL database and every single one of them has to have unique id, so how I can select the specific item that is to be manipulated (changing values via php). the $("#submit").click(function()) will trigger every submit buttons on the page, so how I can the #submit to be some random id that I clicked. There might be a smarter way, but I'm new to this so try to bear with me. thought of passing the unique value with onClick="myfunction(unique_id)", but don't know how it goes with jQuery. hope this made any sense

    Read the article

  • PHP: read all files but randomly?

    - by mathiregister
    hi there, i wonder if there's a way of reading a directory in a random order. With the following code i'm running through the directory thumbs and it's printing images on my website. However, they are always read alphabetically and i wonder if there's a way in doing this randomly? <?php $path = 'thumbs'; if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && $file != '.DS_Store' && $file != 'Thumbs.db') { print "<img class='thumb' src='$path/$file'/>"; } else { //no proper file } } closedir($handle); } ?> thank you for your suggestions! regards

    Read the article

  • Distributing players to tables

    - by IVlad
    Consider N = 4k players, k tables and a number of clans such that each member can belong to one clan. A clan can contain at most k players. We want to organize 3 rounds of a game such that, for each table that seats exactly 4 players, no 2 players sitting there are part of the same clan, and, for the later rounds, no 2 players sitting there have sat at the same table before. All players play all rounds. How can we do this efficiently if N can be about ~80 large? I thought of this: for each table T: repeat until 4 players have been seated at T: pick a random player X that is not currently seated anywhere if X has not sat at the same table as anyone currently at T AND X is not from the same clan as anyone currently at T seat X at T break I am not sure if this will always finish or if it can get stuck even if there is a valid assignment. Even if this works, is there a better way to do it?

    Read the article

  • C++ Program performs better when piped

    - by ET1 Nerd
    I haven't done any programming in a decade. I wanted to get back into it, so I made this little pointless program as practice. The easiest way to describe what it does is with output of my --help codeblock: ./prng_bench --help ./prng_bench: usage: ./prng_bench $N $B [$T] This program will generate an N digit base(B) random number until all N digits are the same. Once a repeating N digit base(B) number is found, the following statistics are displayed: -Decimal value of all N digits. -Time & number of tries taken to randomly find. Optionally, this process is repeated T times. When running multiple repititions, averages for all N digit base(B) numbers are displayed at the end, as well as total time and total tries. My "problem" is that when the problem is "easy", say a 3 digit base 10 number, and I have it do a large number of passes the "total time" is less when piped to grep. ie: command ; command |grep took : ./prng_bench 3 10 999999 ; ./prng_bench 3 10 999999|grep took .... Pass# 999999: All 3 base(10) digits = 3 base(10). Time: 0.00005 secs. Tries: 23 It took 191.86701 secs & 99947208 tries to find 999999 repeating 3 digit base(10) numbers. An average of 0.00019 secs & 99 tries was needed to find each one. It took 159.32355 secs & 99947208 tries to find 999999 repeating 3 digit base(10) numbers. If I run the same command many times w/o grep time is always VERY close. I'm using srand(1234) for now, to test. The code between my calls to clock_gettime() for start and stop do not involve any stream manipulation, which would obviously affect time. I realize this is an exercise in futility, but I'd like to know why it behaves this way. Below is heart of the program. Here's a link to the full source on DB if anybody wants to compile and test. https://www.dropbox.com/s/6olqnnjf3unkm2m/prng_bench.cpp clock_gettime() requires -lrt. for (int pass_num=1; pass_num<=passes; pass_num++) { //Executes $passes # of times. clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &temp_time); //get time start_time = timetodouble(temp_time); //convert time to double, store as start_time for(i=1, tries=0; i!=0; tries++) { //loops until 'comparison for' fully completes. counts reps as 'tries'. <------------ for (i=0; i<Ndigits; i++) //Move forward through array. | results[i]=(rand()%base); //assign random num of base to element (digit). | /*for (i=0; i<Ndigits; i++) //---Debug Lines--------------- | std::cout<<" "<<results[i]; //---a LOT of output.---------- | std::cout << "\n"; //---Comment/decoment to disable/enable.*/ // | for (i=Ndigits-1; i>0 && results[i]==results[0]; i--); //Move through array, != element breaks & i!=0, new digits drawn. -| } //If all are equal i will be 0, nested for condition satisfied. -| clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &temp_time); //get time draw_time = (timetodouble(temp_time) - start_time); //convert time to dbl, subtract start_time, set draw_time to diff. total_time += draw_time; //add time for this pass to total. total_tries += tries; //add tries for this pass to total. /*Formated output for each pass: Pass# ---: All -- base(--) digits = -- base(10) Time: ----.---- secs. Tries: ----- (LINE) */ std::cout<<"Pass# "<<std::setw(width_pass)<<pass_num<<": All "<<Ndigits<<" base("<<base<<") digits = " <<std::setw(width_base)<<results[0]<<" base(10). Time: "<<std::setw(width_time)<<draw_time <<" secs. Tries: "<<tries<<"\n"; } if(passes==1) return 0; //No need for totals and averages of 1 pass. /* It took ----.---- secs & ------ tries to find --- repeating -- digit base(--) numbers. (LINE) An average of ---.---- secs & ---- tries was needed to find each one. (LINE)(LINE) */ std::cout<<"It took "<<total_time<<" secs & "<<total_tries<<" tries to find " <<passes<<" repeating "<<Ndigits<<" digit base("<<base<<") numbers.\n" <<"An average of "<<total_time/passes<<" secs & "<<total_tries/passes <<" tries was needed to find each one. \n\n"; return 0;

    Read the article

  • Randomly generating sequence of ints in a specific range

    - by vvv
    Hi, I am unsure how to put this and my math skills aren't that strong. But here's what I need. I want to generate a list of all the 16bit integers (0-65535). But everytime I do so I want to seed the algorithm randomly that each time the list starts with a different integer and all the subsequent integers will be generated once but also in random order. small example (1-5): ... 1, 5, 3, 2, 4 4, 3, 1, 5, 2 2, 1, 4, 5, 3 ... Any help?

    Read the article

< Previous Page | 29 30 31 32 33 34 35 36 37 38 39 40  | Next Page >