Search Results

Search found 2562 results on 103 pages for 'vector'.

Page 83/103 | < Previous Page | 79 80 81 82 83 84 85 86 87 88 89 90  | Next Page >

  • Matlab Question - Principal Component Analysis

    - by Jack
    I have a set of 100 observations where each observation has 45 characteristics. And each one of those observations have a label attached which I want to predict based on those 45 characteristics. So it's an input matrix with the dimension 45 x 100 and a target matrix with the dimension 1 x 100. The thing is that I want to know how many of those 45 characteristics are relevant in my set of data, basically the principal component analysis, and I understand that I can do this with Matlab function processpca. Could you please tell me how can I do this? Suppose that the input matrix is x with 45 rows and 100 columns and y is a vector with 100 elements.

    Read the article

  • How to make negate_unary work with any type?

    - by Chan
    Hi, Following this question: How to negate a predicate function using operator ! in C++? I want to create an operator ! can work with any functor that inherited from unary_function. I tried: template<typename T> inline std::unary_negate<T> operator !( const T& pred ) { return std::not1( pred ); } The compiler complained: Error 5 error C2955: 'std::unary_function' : use of class template requires template argument list c:\program files\microsoft visual studio 10.0\vc\include\xfunctional 223 1 Graphic Error 7 error C2451: conditional expression of type 'std::unary_negate<_Fn1>' is illegal c:\program files\microsoft visual studio 10.0\vc\include\ostream 529 1 Graphic Error 3 error C2146: syntax error : missing ',' before identifier 'argument_type' c:\program files\microsoft visual studio 10.0\vc\include\xfunctional 222 1 Graphic Error 4 error C2065: 'argument_type' : undeclared identifier c:\program files\microsoft visual studio 10.0\vc\include\xfunctional 222 1 Graphic Error 2 error C2039: 'argument_type' : is not a member of 'std::basic_ostream<_Elem,_Traits>::sentry' c:\program files\microsoft visual studio 10.0\vc\include\xfunctional 222 1 Graphic Error 6 error C2039: 'argument_type' : is not a member of 'std::basic_ostream<_Elem,_Traits>::sentry' c:\program files\microsoft visual studio 10.0\vc\include\xfunctional 230 1 Graphic Any idea? Update Follow "templatetypedef" solution, I got new error: Error 3 error C2831: 'operator !' cannot have default parameters c:\visual studio 2010 projects\graphic\graphic\main.cpp 39 1 Graphic Error 2 error C2808: unary 'operator !' has too many formal parameters c:\visual studio 2010 projects\graphic\graphic\main.cpp 39 1 Graphic Error 4 error C2675: unary '!' : 'is_prime' does not define this operator or a conversion to a type acceptable to the predefined operator c:\visual studio 2010 projects\graphic\graphic\main.cpp 52 1 Graphic Update 1 Complete code: #include <iostream> #include <functional> #include <utility> #include <cmath> #include <algorithm> #include <iterator> #include <string> #include <boost/assign.hpp> #include <boost/assign/std/vector.hpp> #include <boost/assign/std/map.hpp> #include <boost/assign/std/set.hpp> #include <boost/assign/std/list.hpp> #include <boost/assign/std/stack.hpp> #include <boost/assign/std/deque.hpp> struct is_prime : std::unary_function<int, bool> { bool operator()( int n ) const { if( n < 2 ) return 0; if( n == 2 || n == 3 ) return 1; if( n % 2 == 0 || n % 3 == 0 ) return 0; int upper_bound = std::sqrt( static_cast<double>( n ) ); for( int pf = 5, step = 2; pf <= upper_bound; ) { if( n % pf == 0 ) return 0; pf += step; step = 6 - step; } return 1; } }; /* template<typename T> inline std::unary_negate<T> operator !( const T& pred, typename T::argument_type* dummy = 0 ) { return std::not1<T>( pred ); } */ inline std::unary_negate<is_prime> operator !( const is_prime& pred ) { return std::not1( pred ); } template<typename T> inline void print_con( const T& con, const std::string& ms = "", const std::string& sep = ", " ) { std::cout << ms << '\n'; std::copy( con.begin(), con.end(), std::ostream_iterator<typename T::value_type>( std::cout, sep.c_str() ) ); std::cout << "\n\n"; } int main() { using namespace boost::assign; std::vector<int> nums; nums += 1, 3, 5, 7, 9; nums.erase( remove_if( nums.begin(), nums.end(), !is_prime() ), nums.end() ); print_con( nums, "After remove all primes" ); } Thanks, Chan Nguyen

    Read the article

  • problems with matlab wavrecord and wavread

    - by user504363
    Hi all I have a problem in matlab I want to record a speech for 2 seconds then read the recorded sound and plot it I use the code FS = 8000; new_wav = wavrecord(2*FS,FS,'int16'); x = wavread(new_wav); plot(x); but the error appears ??? Error using ==> fileparts at 20 Input must be a row vector of characters. Error in ==> wavread>open_wav at 193 [pat,nam,ext] = fileparts(file); Error in ==> wavread at 65 [fid,msg] = open_wav(file); Error in ==> test at 2 x = wavread(new_wav); I plotted correctly recorded sound files, but when I want to record new one through matlab I get this errors. I tried many ways by changing FS and 'int16' but nothing happens. thanks

    Read the article

  • How to interpolate rotations?

    - by uhuu
    I have two vectors describing rotations; a start rotation A and a target rotation B. How would I best go about interpolating A by a factor F to approach B? Using a simple lerp on the vectors fails to work when more than one dimension needs to be interpolated (i.e. produces undesirable rotations). Maybe building quaternions from the rotation vectors and using slerp is the way to go. But how, then, could I extract a vector describing the new rotation from the resulting quaternion? Thanks in advance.

    Read the article

  • Multiset of shared_ptrs as a dynamic priority queue: Concept and practice

    - by Sarah
    I was using a vector-based priority queue typedef std::priority_queue< Event, vector< Event >, std::greater< Event > > EventPQ; to manage my Event objects. Now my simulation has to be able to find and delete certain Event objects not at the top of the queue. I'd like to know if my planned work-around can do what I need it to, and if I have the syntax right. I'd also like to know if dramatically better solutions exist. My plan is to make EventPQ a multiset of smart pointers to Event objects: typedef std::multi_set< boost::shared_ptr< Event > > EventPQ; I'm borrowing functions of the Event class from a related post on a multimap priority queue. // Event.h #include <cstdlib> using namespace std; #include <set> #include <boost/shared_ptr.hpp> class Event; typedef std::multi_set< boost::shared_ptr< Event > > EventPQ; class Event { public: Event( double t, int eid, int hid ); ~Event(); void add( EventPQ& q ); void remove(); bool operator < ( const Event & rhs ) const { return ( time < rhs.time ); } bool operator > ( const Event & rhs ) const { return ( time > rhs.time ); } double time; int eventID; int hostID; EventPQ* mq; EventPQ::iterator mIt; }; // Event.cpp Event::Event( double t, int eid, int hid ) { time = t; eventID = eid; hostID = hid; } Event::~Event() {} void Event::add( EventPQ& q ) { mq = &q; mIt = q.insert( boost::shared_ptr<Event>(this) ); } void Event::remove() { mq.erase( mIt ); mq = 0; mIt = EventPQ::iterator(); } I was hoping that by making EventPQ a container of pointers, I could avoid wasting time copying Events into the container and avoid accidentally editing the wrong copy. Would it be dramatically easier to store the Events themselves in EventPQ instead? Does it make more sense to remove the time keys from Event objects and use them instead as keys in a multimap? Assuming the current implementation seems okay, my questions are: Do I need to specify how to sort on the pointers, rather than the objects, or does the multiset automatically know to sort on the objects pointed to? If I have a shared_ptr ptr1 to an Event that also has a pointer in the EventPQ container, how do I find and delete the corresponding pointer in EventPQ? Is it enough to .find( ptr1 ), or do I instead have to find by the key (time)? Is the Event::remove() sufficient for removing the pointer in the EventPQ container? There's a small chance multiple events could be created with the same time (obviously implied in the use of multiset). If the find() works on event times, to avoid accidentally deleting the wrong event, I was planning to throw in a further check on eventID and hostID. Does this seem reasonable? (Dumb syntax question) In Event.h, is the declaration of dummy class Event;, then the EventPQ typedef, and then the real class Event declaration appropriate? I'm obviously an inexperienced programmer with very spotty background--this isn't for homework. Would love suggestions and explanations. Please let me know if any part of this is confusing. Thanks.

    Read the article

  • Can I write functors using a private nested struct?

    - by Kristo
    Given this class: class C { private: struct Foo { int key1, key2, value; }; std::vector<Foo> fooList; }; The idea here is that fooList can be indexed by either key1 or key2 of the Foo struct. I'm trying to write functors to pass to std::find so I can look up items in fooList by each key. But I can't get them to compile because Foo is private within the class (it's not part of C's interface). Is there a way to do this without exposing Foo to the rest of the world? (note: I've got to run to a meeting. I'll be able to post more sample code in about a half hour.)

    Read the article

  • How might I assume a "default value" when parsing using boost::spirit?

    - by tJener
    Let's say I have a grammar defined to something like: a b c d where c, and d are optional and default to 14 if not given. Can I get it to automatically return the 14 if the value isn't given? The closest I've come is like the following: qi::rule<Iterator, std::vector<int>(), ascii::space_type> some_rule; some_rule %= >> int_ >> int_ >> -int_ >> -int_; // ... some_other_rule = some_rule[&some_callback_for_int_vectors]; which will then get 0 for the optional values that didn't show up (I believe). I then change consecutive 0s at the end into 14. Not only is this horribly wrong, but its also just not elegant. Is there a better way to do this?

    Read the article

  • CSV parser in C++

    - by User1
    All I need is a good CSV file parser for C++. At this point it can really just be a comma-delimited parser (ie don't worry about escaping new lines and commas). The main need is a line-by-line parser that will return a vector for the next line each time the method is called. I found this article which looks quite promising: http://www.boost.org/doc/libs/1_35_0/libs/spirit/example/fundamental/list_parser.cpp I've never used Boost's Spirit, but am willing to try it. Is it overkill/bloated or is it fast and efficient? Does anyone have faster algorithms using STL or anything else? Thanks!

    Read the article

  • WPF tabswitch/ render takes too much time..

    - by Socrates
    I have a WPF application with many tabs.. in one tab.. i make a verycomplex vector drawing consisting of thousands of drawing visuals.. (this represents a machine and all elements need to be interactable..) It takes 3/4 seconds for drawing this for the first time..After the first draw it should be done.. The problem is if i switch to another tab and comeback, it takes atlease 2,3 seconds to show the tabpage with drawing again.. Since there is no redraw, why should it take so much time..?

    Read the article

  • Uniform distribution of binary values in Matlab

    - by JohnIdol
    I have a requirement for the generation of a given number N of vectors of given size each consistent of a uniform distribution of 0s and 1s. This is what I am doing at the moment, but I noticed that the distribution is strongly peaked at half 1s and half 0s, which is no good for what I am doing: a = randint(1, sizeOfVector, [0 1]); The unifrnd function looks promising for what I need, but I can't manage to understand how to output a binary vector of that size. Is it the case that I can use the unifrnd function (and if so how would be appreciated!) or can is there any other more convenient way to obtain such a set of vectors? Any help appreciated!

    Read the article

  • Distance between hyperplanes

    - by michael dillard
    I'm trying to teach myself some machine learning, and have been using the MNIST database (http://yann.lecun.com/exdb/mnist/) do so. The author of that site wrote a paper in '98 on all different kinds of handwriting recognition techniques, available at http://yann.lecun.com/exdb/publis/pdf/lecun-98.pdf. The 10th method mentioned is a "Tangent Distance Classifier". The idea being that if you place each image in a (NxM)-dimensional vector space, you can compute the distance between two images as the distance between the hyperplanes formed by each where the hyperplane is given by taking the point, and rotating the image, rescaling the image, translating the image, etc. I can't figure out enough to fill in the missing details. I understand that most of these are indeed linear operators, so how does one use that fact to then create the hyperplane? And once we have a hyperplane, how do we take its distance with other hyperplanes?

    Read the article

  • RODBC string getting truncated

    - by sayan dasgupta
    Hi all, I am fetching data from MySql Server into R using RODBC. So in one column of the database is a character vector SELECT MAX(CHAR_LENGTH(column)) FROM reqtable; RETURNS 26566 Now I will show you an example how I am running into the problem `library(RODBC) con <- odbcConnect("mysqlcon") rslts <- as.numeric(sqlQuery(con, "SELECT CHAR_LENGTH(column) FROM reqtable LIMIT 10", as.is=TRUE)[,1]) ` returns > rslts [1] 62 31 17 103 30 741 28 73 25 357 where as rslts <- nchar(as.character(sqlQuery(con, "SELECT column FROM reqtable LIMIT 10", as.is=TRUE)[,1])) returns > rslts [1] 62 31 17 103 30 255 28 73 25 255 So strings with length 255 is getting truncated at 255. Is there a way I can get the full string. Thanks

    Read the article

  • C++ refactor common code with one different statement

    - by user231536
    I have two methods f(vector<int>& x, ....) and g(DBConn& x, ....) where the (....) parameters are all identical. The code inside the two methods are completely identical except for one statement where we do different actions based on the type of x: in f(): we do x.push_back(i) in g(): we do x.DeleteRow(i) What is the simplest way to extract the common code into one method and yet have the two different statements? I am thinking of having a templated functor that overloads operator () (int a) but that seems overkill.

    Read the article

  • Multiplying Block Matrices in Numpy

    - by Ada Xu
    Hi Everyone I am python newbie I have to implement lasso L1 regression for a class assignment. This involves solving a quadratic equation involving block matrices. minimize x^t * H * x + f^t * x where x 0 Where H is a 2 X 2 block matrix with each element being a k dimensional matrix and x and f being a 2 X 1 vectors each element being a k dimension vector. I was thinking of using nd arrays. such that np.shape(H) = (2, 2, k, k) np.shape(x) = (2, k) But I figured out that np.dot(X, H) doesn't work here. Is there an easy way to solve this problem? Thanks in advance.

    Read the article

  • Read multiple strings from a file C++

    - by user69514
    Hi I need to read different values stored in a file one by one. So I was thinking I can use ifstream to open the file, but since the file is set up in such a way that a line might contain three numbers, and the other line one number or two numbers I'm not sure how to read each number one by one. I was thinking of using stringstream but I'm not sure if that would work. The file is a format like this. 52500.00 64029.50 56000.00 65500.00 53780.00 77300.00 44000.50 80100.20 90000.00 41000.00 60500.50 72000.00 I need to read each number and store it in a vector. What is the best way to accomplish this? Reading one number at a time even though each line contains a different amount of numbers?

    Read the article

  • Reducing template bloat with inheritance

    - by benoitj
    Does anyone have experience reducing template code bloat using inheritance? i hesitate rewriting our containers this way: class vectorBase { public: int size(); void clear(); int m_size; void *m_rawData; //.... }; template< typename T > class vector : public vectorBase { void push_back( const T& ); //... }; I should keep maximum performance while reducing compile time I'm also wondering why stl implementations do not uses this approach Thanks for your feedbacks

    Read the article

  • C++ - Where to code a member function for an inherited object.

    - by Francisco P.
    Hello! I have a few classes (heat, gas, contact, pressure) inheriting from a main one (sensor). I have a need to store them in a vector<Sensor *> (part of the specification). At some point in time, I need to call a function that indiscriminately stores those Sensor *. (also part of the specification, not open for discussion) Something like this: for(size_t i = 0; i < Sensors.size(); ++i) Sensors[i]->storeSensor(os) //os is an ofstream kind of object, passed onwards by reference Where and how shall storeSensor be defined? Is there any simple way to do this or will I need to disregard the specification? Mind you, I'm a beginner! Thanks for your time!

    Read the article

  • Whats wrong with the following code, its not compiling

    - by Ganesh Kundapur
    #include <iostream> #include <vector> using namespace std; class Base { public: void Display( void ) { cout<<"Base display"<<endl; } int Display( int a ) { cout<<"Base int display"<<endl; return 0; } }; class Derived : public Base { public: void Display( void ) { cout<<"Derived display"<<endl; } }; void main() { Derived obj; obj.Display(); obj.Display( 10 ); } $test1.cpp: In function ‘int main()’: test1.cpp:35: error: no matching function for call to ‘Derived::Display(int)’ test1.cpp:24: note: candidates are: void Derived::Display() On commenting obj.Display(10), it works.

    Read the article

  • Pass data in np.dnarray to Highcharts

    - by F.N.B
    I'm working with python 2.7, jinja2, flask and Highcharts. I create two numpy array (x1 and x2, type = numpy.dnarray) and I pass to Highcharts. My problems is, Highcharts don't recognize the commas in the vector. This is my jinja2 code: <script> $(function () { $('#container').highcharts({ series: [{ name: 'Tokyo', data: {{ x1 }} }, { name: 'London', data: {{ x2 }} }] }); }); And this is the error that I look with network chrome dev tools: series: [{ name: 'Tokyo', data: [1 4 5 2 3] }, { name: 'London', data: [3 6 7 4 1] }] I need change the numpy array to python list to pass to Highcharts or there is a better way to do?? Thanks

    Read the article

  • custom Filter Android won't show me the results

    - by TiGer
    Hi, I have been implementing a class which class extends ArrayAdapter and implements Filterable. The filtering part (in the performFiltering method()) seems to go ok, it fills the FilterResults object just as expected. But then I think I'm not doing it right on how to publish the results, atm I have : protected void publishResults(CharSequence prefix, FilterResults results) { // NOTE: this function is *always* called from the UI thread. subItems = (Vector)results.values; notifyDataSetChanged(); } But this simply won't "populate" my List with the received data. So now my question is how do I populate my List with the received results ? Do I have to do that programmatically ?

    Read the article

  • Java ME Application running fine in Emulator but crashing when deployed to N70. Any way to identify

    - by sana
    I have developed a Java ME application for CLDC platform. It works fine when executed in an emulator. But when i deploy it to my N70 phone the application doesn't start at all in the phone. In my application there are some 14 classes and am creating an instance of each and putting them in the vector on application start. The classes just have one variable and 2 methods. Can this creating of lot of instances be the reason for its crashing? Is there any way I can find out the reason why the application is not able to start in the phone?

    Read the article

  • do.call(rbind, list) for uneven number of column

    - by h.l.m
    I have a list, with each element being a character vector, of differing lengths I would like to bind the data as rows, so that the column names 'line up' and if there is extra data then create column and if there is missing data then create NAs Below is a mock example of the data I am working with x <- list() x[[1]] <- letters[seq(2,20,by=2)] names(x[[1]]) <- LETTERS[c(1:length(x[[1]]))] x[[2]] <- letters[seq(3,20, by=3)] names(x[[2]]) <- LETTERS[seq(3,20, by=3)] x[[3]] <- letters[seq(4,20, by=4)] names(x[[3]]) <- LETTERS[seq(4,20, by=4)] The below line would normally be what I would do if I was sure that the format for each element was the same... do.call(rbind,x) I was hoping that someone had come up with a nice little solution that matches up the column names and fills in blanks with NAs whilst adding new columns if in the binding process new columns are found...

    Read the article

  • The C vs. C++ way

    - by amc
    Hi, So I have to write a program that will iterate through an image and record the pixel locations corresponding to each color pixel that appears in it. For example, given http://www.socuteurl.com/fishywishykissy I need to find the coordinates of all yellow, purple, dark pink, etc pixels. In C++ I would use a hash table to do this. I would iterate through the image, check each pixel's value, look up that value and either add to a vector of pixel coordinates if it were found or add a new entry to the table if the value were not already there. The problem is that I may need to write this program in pure C instead of C++. How would I go about doing this in C? I feel like implementing a hash table would be pretty obnoxious and error-prone: should I avoid doing that? I'm pretty inexperienced with C and have a fair amount of C++ experience, if that matters. Thanks.

    Read the article

  • R: Cut and labels/breaks length conflict

    - by AkselO
    I am working with the cut function to prep data for a barplot histogram but keep running into a seeming inconsistency between my labels and breaks: Error in cut.default(sample(1:1e+05, 500, T), breaks = sq, labels = sprintf("$%.0f", : labels/breaks length conflict Here is an example. I pretend that it is income data, using a sequence of 0 to $100,000 in bins of $10,000. I use the same variable to generate both breaks and labels, with minor formating on the label side. I thought they might for some reason have different lengths when comparing to a character vector, but they appear to have the same length, still. > sq<-seq(0,100000,10000) > cut(sample(1:100000, 500, T),breaks=sq,labels=sprintf("$%.0f",sq)) > length(sprintf("$%.0f",sq)) [1] [11] > length(sq) [1] [11]

    Read the article

  • Autocomplete for generic types in Eclipse

    - by AvrDragon
    "Refer to objects by their interfaces" is a good practise, as mentioned in Effective Java. So for example i prefer List<String> al = new ArrayList<String>(); over ArrayList<String> al = new ArrayList<String>(); in my code. One annoying thing is that if i type ArrayList<String> al = new and then hit Ctrl+Space in Eclipse i get ArrayList<String>() as propostal. But if i type List al = new and then hit Ctrl+Space i will get only propostal to define anonymous inner class, but not propostals such as new ArrayList<String>(), what is 99% the case, or for example new Vector<String>(). Is there any way to get the subclasses as propostals for generic types?

    Read the article

< Previous Page | 79 80 81 82 83 84 85 86 87 88 89 90  | Next Page >