logo
down
shadow

All possible combinations of n items selected randomly from a set of x items (algorithm)


All possible combinations of n items selected randomly from a set of x items (algorithm)

By : Darren
Date : January 10 2021, 01:57 PM
wish help you to fix your issue Choosing p out of n items, this is the formula to tell you how many combinations there are.
code :


Share : facebook icon twitter icon
Algorithm - generating all combinations from items that must be chosen in sequence

Algorithm - generating all combinations from items that must be chosen in sequence


By : user3782546
Date : March 29 2020, 07:55 AM
this one helps. It's a cartesian product, if exactly one item is chosen from each list/array, more precisely a list of the elements of the cartesian product. For lists, it's in Haskell's standard library:
code :
Prelude> sequence ["abc","def","ghi"]
["adg","adh","adi","aeg","aeh","aei","afg","afh","afi","bdg","bdh","bdi","beg","beh"
,"bei","bfg","bfh","bfi","cdg","cdh","cdi","ceg","ceh","cei","cfg","cfh","cfi"]
algorithm to get all combinations of splitting up N items into K bins

algorithm to get all combinations of splitting up N items into K bins


By : user3810183
Date : March 29 2020, 07:55 AM
Hope that helps A common approach is as follows.
If you have, say, K bins, then add K-1 special values to your initial array. I will use the -1 value assuming that it never occurs in the initial array; you can choose a different value.
code :
[-1,1,2,3,4] -> {{}, {1,2,3,4}}
[2,1,3,-1,4] -> {{2,3,4}, {4}}
[3,1,2,-1,4] -> {{3,1,2}, {4}}
[1,3,-1,2,4] -> {{1,3}, {2,4}}
Efficient algorithm to get the combinations of all items in object

Efficient algorithm to get the combinations of all items in object


By : JEGAN
Date : March 29 2020, 07:55 AM
hope this fix your issue Your algorithm is almost O(2^n), you can discard a lot of combinations, but the num of elements will be (n! * (n-x)!) / x!.
To discard the useless combinations you can use an indexed array.
code :
 function combine(items, numSubItems) {
        var result = [];
        var indexes = new Array(numSubItems);
        for (var i = 0 ; i < numSubItems; i++) {
            indexes[i] = i;
        }
        while (indexes[0] < (items.length - numSubItems + 1)) {
            var v = [];
            for (var i = 0 ; i < numSubItems; i++) {
                v.push(items[indexes[i]]);
            }
            result.push(v);
            indexes[numSubItems - 1]++;
            var l = numSubItems - 1; // reference always is the last position at beginning
            while ( (indexes[numSubItems - 1] >= items.length) && (indexes[0] < items.length - numSubItems + 1)) {
                l--; // the last position is reached
                indexes[l]++;
                for (var i = l +1 ; i < numSubItems; i++) {
                    indexes[i] = indexes[l] + (i - l);
                }
            }        
        }
        return result;
    }

    var combinations = combine(["a", "b", "c", "d"], 3);
    console.log(JSON.stringify(combinations));
Optimum algorithm to check various combinations of items when number of items is too large

Optimum algorithm to check various combinations of items when number of items is too large


By : OlegMihaylov
Date : March 29 2020, 07:55 AM
hop of those help? The idea is to replace the computation of alpha with the so-called discrimination for each item from classical test theory (CTT). The discrimination is the correlation of the item score with a "true score" (which we would assume to be the row sum).
Let the data be
code :
dat <-  structure(list(CESD1 = c(1, 2, 2, 0, 1, 0, 0, 0, 0, 1), CESD2 = c(2, 3, 1, 0, 0, 1, 1, 1, 0, 1), 
                       CESD3 = c(0, 3, 0, 1, 1, 0, 0, 0, 0, 0), CESD4 = c(1, 2, 0, 1, 0, 1, 1, 1, 0, 0), 
                       CESD5 = c(0, 1, 0, 2, 1, 2, 2, 0, 0, 0), CESD6 = c(0, 3, 0, 1, 0, 0, 2, 0, 0, 0), 
                       CESD7 = c(1, 2, 1, 1, 2, 0, 1, 0, 1, 0), CESD8 = c(1, 3, 1, 1, 0, 1, 0, 0, 1, 0), 
                       CESD9 = c(0, 1, 0, 2, 0, 0, 1, 1, 0, 1), CESD10 = c(0, 1, 0, 2, 0, 0, 1, 1, 0, 1), 
                       CESD11 = c(0, 2, 1, 1, 1, 1, 2, 3, 0, 0), CESD12 = c(0, 3, 1, 1, 1, 0, 2, 0, 0, 0), 
                       CESD13 = c(0, 3, 0, 2, 1, 2, 1, 0, 1, 0), CESD14 = c(0, 3, 1, 2, 1, 1, 1, 0, 1, 1), 
                       CESD15 = c(0, 2, 0, 1, 0, 1, 0, 1, 1, 0), CESD16 = c(0, 2, 2, 0, 0, 1, 1, 0, 0, 0), 
                       CESD17 = c(0, 0, 0, 0, 0, 1, 1, 0, 0, 0), CESD18 = c(0, 2, 0, 0, 0, 0, 0, 0, 0, 1), 
                       CESD19 = c(0, 3, 0, 0, 0, 0, 0, 1, 1, 0), CESD20 = c(0, 3, 0, 1, 0, 0, 0, 0, 0, 0)), 
                  .Names = c("CESD1", "CESD2", "CESD3", "CESD4", "CESD5", "CESD6", "CESD7", "CESD8", "CESD9", 
                             "CESD10", "CESD11", "CESD12", "CESD13", "CESD14", "CESD15", "CESD16", "CESD17", 
                             "CESD18", "CESD19", "CESD20"), row.names = c(NA, -10L), 
                  class = c("tbl_df", "tbl", "data.frame"))
stat <- t(sapply(1:ncol(dat), function(ii){
  dd <- dat[, ii]
  # discrimination is the correlation of the item to the rowsum
  disc <- if(var(dd, na.rm = TRUE) > 0) cor(dd, rowSums(dat[, -ii]), use = "pairwise")
  # alpha that would be obtained when we skip this item
  alpha <- psych::alpha(dat[, -ii])$total$raw_alpha
  c(disc, alpha)
  }))
dimnames(stat) <- list(colnames(dat), c("disc", "alpha^I"))
stat <- data.frame(stat)
plot(stat, pch = 19)
stat <- stat[order(stat$disc), ]
this <- sapply(1:(nrow(stat)-2), function(ii){
  ind <- match(rownames(stat)[1:ii], colnames(dat))
  alpha <- psych::alpha(dat[, -ind, drop = FALSE])$total$raw_alpha
})

delete_these <- rownames(stat)[which(this > .9)]
psych::alpha(dat[, -match(delete_these, colnames(dat)), drop = FALSE])$total$raw_alpha
length(delete_these)
stat <- stat[order(stat$disc, decreasing = TRUE), ]
this <- sapply(1:(nrow(stat)-2), function(ii){
  ind <- match(rownames(stat)[1:ii], colnames(dat))
  alpha <- psych::alpha(dat[, -ind, drop = FALSE])$total$raw_alpha
})

delete_these <- rownames(stat)[which(this > .9)]
psych::alpha(dat[, -match(delete_these, colnames(dat)), drop = FALSE])$total$raw_alpha
length(delete_these)
After items selection in my ListView other items get randomly selected while scrolling Kotlin

After items selection in my ListView other items get randomly selected while scrolling Kotlin


By : user3196113
Date : March 29 2020, 07:55 AM
Hope this helps You don't appear to be changing the ListView's Cursor after you have made changes to/updated the underlying data.
Try, after making changes to the underlying data, updating the ListView's Cursor by
code :
public class MainActivity extends AppCompatActivity {

    DBHelper dbhelper;
    ListView myListView;
    MyCursorAdapter myAdapter;
    Cursor mCursor;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myListView = this.findViewById(R.id.myListView);
        dbhelper = new DBHelper(this);
        addSomeTestingData();
        manageListView();
    }

    private void manageListView() {
        mCursor = dbhelper.getAllRows();
        if (myAdapter == null) {
            myAdapter = new MyCursorAdapter(this,mCursor);
            myListView.setAdapter(myAdapter);
            myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    dbhelper.updateSelected(mCursor.getString(mCursor.getColumnIndex(ContractClass.FeedReaderContract.COLUMN_NAME_ENWORD)));
                    manageListView();
                }
            });
        } else {
            myAdapter.swapCursor(mCursor);
        }
    }

    private void addSomeTestingData() {

        if (DatabaseUtils.queryNumEntries(dbhelper.getWritableDatabase(),ContractClass.FeedReaderContract.TABLENAME) > 1) return;
        for (int i=0; i < 10; i++) {
            dbhelper.addRow("Apple", "Thing that falls from trees");
            dbhelper.addRow("Cat", "Something that is furry and sits on mats");
            dbhelper.addRow("Bear", "Something that is furry that eats honey but doesn't ssit on a mat");
            dbhelper.addRow("Dog", "Something is furry and friendly");
            dbhelper.addRow("Echida", "An upside down hedgehog");
            dbhelper.addRow("Ferret", "Something that is furry and found up trouser legs");
            dbhelper.addRow("Giraffe", "Something that has 5 legs one pointing up");
            dbhelper.addRow("Hippo", "An animal that loves mud and water but not humans");
            dbhelper.addRow("Ibis", "A white feathered flying thing");
            dbhelper.addRow("Jaguar", "A car or a large black cat");
            dbhelper.addRow("Kangaroo", "A marsupial that boxes, skips and has a puch for shopping trips");
            dbhelper.addRow("Lizard", "A rock dweller");
            dbhelper.addRow("Mammoth", "A big hairy elephant now extinct");
            dbhelper.addRow("Nuthatch", "A small bird that does not customise nuts so they have hatches.");
            dbhelper.addRow("Ostrich", "A l argefast running bird that does not fly");
            dbhelper.addRow("Panther", "A skinny pink cat that walks on only two of it's four lehs");
            dbhelper.addRow("Queen", "A female rule of a country");
            dbhelper.addRow("Rhinocerous", "A Hippo like animal that has a name that is hard to spell");
            dbhelper.addRow("Tiger", "A live verion of Winnie the Pooh's friend Tigger");
            dbhelper.addRow("Stork", "A skinny ostrich that flies and delivers children through Dream World.");
        }
    }
}
public class DBHelper extends SQLiteOpenHelper {

    public DBHelper(@Nullable Context context) {
        super(context, ContractClass.DBNAME,null,ContractClass.DBVERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(ContractClass.FeedReaderContract.CRTSQL);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    public Cursor getAllRows() {
        SQLiteDatabase db = this.getWritableDatabase();
         return db.query(ContractClass.FeedReaderContract.TABLENAME,null,null,null,null,null,null);
    }

    public void updateSelected(String selected) {
        SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL("UPDATE "
                        + ContractClass.FeedReaderContract.TABLENAME
                        + " SET " + ContractClass.FeedReaderContract.COLUMN_NAME_SELECTED
                        + "= CASE " + ContractClass.FeedReaderContract.COLUMN_NAME_SELECTED +
                        " WHEN 1 THEN 0 ELSE 1 END " +
                        " WHERE " + ContractClass.FeedReaderContract.COLUMN_NAME_ENWORD + " LIKE ?",
                new String[]{selected}
        );
    }

    public long addRow(String enWord, String definition) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(ContractClass.FeedReaderContract.COLUMN_NAME_ENWORD,enWord);
        cv.put(ContractClass.FeedReaderContract.COLUMN_NAME_DEFN,definition);
        return db.insert(ContractClass.FeedReaderContract.TABLENAME,null,cv);
    }
}
public class MyCursorAdapter extends CursorAdapter {

    public MyCursorAdapter(Context context, Cursor c) {
        super(context, c, false);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        return LayoutInflater.from(context).inflate(R.layout.row_list_row,parent,false);
    }


    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        if (cursor.getInt(cursor.getColumnIndex(ContractClass.FeedReaderContract.COLUMN_NAME_SELECTED)) < 1) {
            view.setBackgroundColor(0xFFF9F9F9);
        } else {
            view.setBackgroundColor(0xFFD9D9D9);
        }
        TextView tvBody = view.findViewById(R.id.txtName);
        TextView tvPriority = view.findViewById(R.id.txtComment);
        TextView tvPriority2 = view.findViewById(R.id.txtThird);
        TextView tvPriority3 = view.findViewById(R.id.txtThi);
        tvBody.setText(cursor.getString(cursor.getColumnIndex(ContractClass.FeedReaderContract.COLUMN_NAME_ENWORD)));
        tvPriority.setText(cursor.getString(cursor.getColumnIndex(ContractClass.FeedReaderContract.COLUMN_NAME_DEFN)));
        tvPriority2.setText(cursor.getString(cursor.getColumnIndex(ContractClass.FeedReaderContract._id)));
        tvPriority3.setText(cursor.getString(cursor.getColumnIndex(ContractClass.FeedReaderContract.COLUMN_NAME_SELECTED)));
    }
}
Related Posts Related Posts :
  • Looking for a .Net ORM
  • Cost of SortedDictionary.Count
  • Displaying process percentage on DOS screen
  • C# Importing Large Volume of Data from CSV to Database
  • c# control location precision
  • Printing to Zebra printer gives faint and blurry images
  • How to avoid stepping into dll code file?
  • Programmaticaly prevent Vista desktop search (WDS) from indexing pst files placed on mapped network drives
  • Is there anyway to reduce IsolatedStorage capacity in Silverlight?
  • C#: How to print a unicode string to console?
  • Frequency Table with Random Values
  • My Visual Studio 2008 web application keeps throwing a .Net error when I first run it, but refreshing fixes it
  • TCP Connection Creation and Closing Event Hooking
  • Find changed properties of a class
  • C#: Object with custom marshaller not containing data after PInvoke call
  • Version Control System with API. Need to get metrics
  • Performance comparison of Dictionaries
  • How to get process name and title of the top window on Windows / C#
  • How to save the ListView contents to a text file?
  • Why not .NET-style delegates rather than closures in Java?
  • Get CLSID by PIA interface Type
  • Visual Studio 2008 C# - Recover solution from application manifest possible?
  • Is a good practice to initialize private data members from within ctor by calling the associated properties instead of t
  • Inserting into a bitstream
  • How do you write byte[] array using log4.net
  • Clickonce + .NET client profile 4 framework + offline
  • Show form that showDialog from mainForm won't block it, but closing mainForm will close it
  • Developing a GPS car tracking system
  • dynamic log4net appender name?
  • Visual studio formatting issue
  • IndexOutOfRangeException when a stream is a multiple of the buffer size
  • How to deal with calculated values with Dependency Properties on a custom WPF control
  • counting from textbox,asp.net
  • Threading best practice when using SFTP in C#
  • how to load PDF file in website page using C#
  • Parent child class relationship design pattern
  • MessageQueue.BeginReceive() null ref error - c#
  • A C# collection, which behaves like C++ set or priority_queue?
  • Animating WPF buttons from inside a style
  • WPF Grid : GridSplitter event
  • Server 2008 Task Scheduler Mapped Drive Access C#
  • Cast problem with LINQ
  • Combo box Item source = ObservableCollection & I need a '-None-' dummy entry at the top
  • Which GUI control is suitable for this purpose?
  • Trying to access App.config file for mail settings but fails to work
  • Invoke PowerShell script from c# in runspace and get line number where error occured
  • How to show html contents with a RichTextBox?
  • FTP monitoring and downloading of new files
  • MEF + Plug-In not updating
  • Efficient handling of super wide, but not so tall, bitmap?
  • .NET 3.0 Unit Testing getting System.MethodAccessException calling .NET 2.0
  • Web Services vs Persistent Sockets
  • How do I dynamically reference incremented properties in C#?
  • Windows Installer (C#) error code 2869
  • Exception "The operation is not valid for the state of the transaction" using TransactionScope
  • Tools for listing database accesses from .NET code
  • Excel VSTO set selection
  • Creating a subscription based website in ASP.NET
  • Merging Resources Dictionaries
  • How to launch a .bat file in a C# windows Service project
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk