id
stringlengths
36
36
text
stringlengths
1
1.25M
5a26a0c5-2c81-43aa-aeb9-06ed3c82e740
public int getKarma(String name){ try{ PreparedStatement selectPlayer = connection.prepareStatement("SELECT * FROM Player WHERE name=?"); selectPlayer.setString(1, name); ResultSet result = selectPlayer.executeQuery(); result.next(); return result.get...
0c1a982a-eaf9-432b-b8db-ce68f38bfce0
public Database() { this.connected = false; this.connection = null; }
2f2478ed-0381-4dd8-a8f4-23d6498f582c
protected Statements getStatement(String query) { String trimmedQuery = query.trim(); if (trimmedQuery.substring(0,6).equalsIgnoreCase("SELECT")) return Statements.SELECT; else if (trimmedQuery.substring(0,6).equalsIgnoreCase("INSERT")) return Statements.INSERT; else if (trimmedQuery.substring(0,6).equals...
6694ede0-d049-446a-8acd-17d473b0c2bc
public KarmaTopCommandExecutor(Karma instance){ plugin = instance; }
5580df30-4b8c-4f33-9732-111871cc8f00
@Override public boolean onCommand(final CommandSender sender, Command cmd, String label, final String[] args) { Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { @Override public void run() { if(args.length > 0){ sender.sendMe...
2cdba6e9-da7e-4627-a604-f9feaa8df51d
@Override public void run() { if(args.length > 0){ sender.sendMessage("usage: /karmatop"); } else { int top = plugin.getConfig().getInt("top"); String message = top(top); if(message!=null){ ...
611711d2-43bb-4b14-ad1e-10d22183a7bc
private String top(int top){ String message = ""; PooledConnection connection = plugin.getMyDatabase().getConnection(); String query = "SELECT * FROM Player ORDER BY karma DESC"; try{ ResultSet result = connection.query(query); int counter = 1; while(result.next() && counter <=plugin.getTop()){ ...
c67a4894-2d29-47f0-b936-ac83266c8d8a
public KarmaGiveCommandExecutor(Karma instance){ plugin = instance; }
53117e8f-e696-4e30-872f-610020d59d9b
@Override public boolean onCommand(final CommandSender sender, Command cmd, String label, final String[] args) { Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { @Override public void run() { String adminName = sender.getName(); i...
cbc51e21-0686-4fa4-85fb-5af27248d3b5
@Override public void run() { String adminName = sender.getName(); if(args.length<1){ sender.sendMessage("usage: /karmagive <player> [reason]"); } else { if(args.length > 1) { String message = giv...
11585857-2cb1-4d27-9df0-069baa1f4132
private String getReason(String[] args){ String reason = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " "); reason = reason.trim(); return reason; }
c94f0134-57c2-4a22-9fe6-e7c6a714d3e8
private String giveKarma(String admin, String arg, String reason){ PooledConnection connection = plugin.getMyDatabase().getConnection(); String message = null; try{ String name = connection.autoComplete(arg); if(name != null){ if(connection.transaction(name, admin, 1, plugin.getCoolDown(),reason)){ ...
ea73232f-6d35-4331-a57e-719f12b8af6d
public KarmaCommandExecutor(Karma instance){ plugin = instance; }
cb927a13-95fd-4d71-b93b-0e7a94f293a7
@Override public boolean onCommand(final CommandSender sender, Command cmd, String label, final String[] args) { Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { @Override public void run() { if(sender instanceof Player){ Play...
ea89c107-d107-4dc0-ade4-20177e4cf61f
@Override public void run() { if(sender instanceof Player){ Player player = (Player)sender; if(args.length == 0){ String name = player.getName(); sender.sendMessage(Message.getDisplay(plugin, name, getKa...
6c2fb4d5-aef7-4a10-9480-e120f9dfc7a5
private int getKarma(String name){ PooledConnection connection = plugin.getMyDatabase().getConnection(); int karma = 0; try{ karma = connection.getKarma(name); } catch(Exception e){ e.printStackTrace(); } finally { connection.close(); } return karma; }
4553f332-76e8-43d9-8c48-2036307c346e
private String view(String arg){ PooledConnection connection = plugin.getMyDatabase().getConnection(); String message = ""; try{ String name = connection.autoComplete(arg); if(name != null){ message = Message.getView(plugin, name, connection.getKarma(name)); }else { message = Message.getNo...
cefc9a3f-8b6f-4e94-879d-071687f28035
public KarmaTakeCommandExecutor(Karma instance){ plugin = instance; }
3912b94a-c713-4b6a-bdc2-e432373bb46e
@Override public boolean onCommand(final CommandSender sender, Command cmd, String label, final String[] args) { Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { @Override public void run() { String adminName = sender.getName(); ...
d2ad3232-f775-4749-877f-9b87cb78c9e6
@Override public void run() { String adminName = sender.getName(); if(args.length<1){ sender.sendMessage("usage: /karmatake <player> [reason]"); } else { if(args.length > 1){ String message = giv...
6f83faa3-6ceb-4c9d-a8ee-f00019b00970
private String getReason(String[] args){ String reason = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " "); reason = reason.trim(); return reason; }
16faf823-baf8-471a-b40f-0d75093eca50
private String giveKarma(String admin, String arg, String reason){ PooledConnection connection = plugin.getMyDatabase().getConnection(); String message = null; try{ String name = connection.autoComplete(arg); if(name != null){ if(connection.transaction(name, admin, -1, plugin.getCoolDown(), reason)){ ...
b6aae042-a6f5-443b-bcf1-f586cbc23eb8
public PlayerLoginListener (Karma instance){ plugin = instance; }
306b59de-28fe-4122-8c0e-86605fa100b4
@EventHandler public void onPlayerLogin(PlayerLoginEvent event){ final MySQLDatabase mysql = plugin.getMyDatabase(); final String name = event.getPlayer().getName(); plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { public void run() { PooledCon...
cbb1e055-94df-41bd-9236-da8379ade850
public void run() { PooledConnection connection = mysql.getConnection(); try { //Use prepared Statements to avoid SQL Injection PreparedStatement selectPlayer = connection.getSQLConnection().prepareStatement("SELECT * FROM Player WHERE name=?"); ...
4c57b2e6-a97d-4fb3-aa7e-d6d4c24104ec
public ArrayList<ArrayList<Integer>> combine(int n, int k) { // ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>(); // // for(int i = 1; i <= n - 1; i++){ // ArrayList<ArrayList<Integer>> temp = new ArrayList<ArrayList<Integer>>(); // for(int j = i + 1; j <= n; j++){ // ArrayList<Integer...
e4d3fa80-3750-438b-bccd-02111c29e730
private ArrayList<ArrayList<Integer>> combine(int s, int e, int n){ ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>(); if(e > n){ ret.add(new ArrayList<Integer>()); return ret; } for(int i = s; i <= e; i++){ ...
2cffebdd-042a-47c3-b475-3fa434e604aa
public static void main(String[] args){ Combinations c = new Combinations(); ArrayList<ArrayList<Integer>> result = c.combine(4, 2); for(ArrayList<Integer> l : result){ CombinationSumTwo.printList(l); } }
8cf17f91-50f8-41f0-9300-c365ce83f25c
ListNode(int x) { val = x; next = null; }
f75e88c0-ba0a-4249-a843-5d6a5d7982c2
public void solve(char[][] board) { HashMap<Index, Boolean> currTrav = new HashMap<Index, Boolean>(); for(int i = 0; i < board.length; i++){ for(int j = 0; j < board[0].length; j++){ if(board[i][j] == 'O'){ currTrav.clear(); In...
dbbe5dde-1009-482f-bbcb-758db384262f
private boolean check(char[][] board, Index curr, HashMap<Index, Boolean> traved){ boolean res = true; for(Index ind : curr.getNear()){ if(outOfRange(ind, board[0].length, board.length)){ return false; } else if(board[ind.getX()][ind.getY()] == 'O' && !trave...
935a088d-0c0e-426f-b8bf-ea32ffe44287
private boolean outOfRange(Index ind, int width, int height){ return ind.getY() < 0 || ind.getY() > width - 1 || ind.getX() < 0 || ind.getX() > height - 1; }
bf6e2dad-cc7e-448e-9804-cabaf9f14f75
public Index(int x, int y) { this.x = x; this.y = y; }
1aac6d6d-b3d9-426b-8871-874ce7641e57
public int getX(){ return this.x; }
c735c7e6-58c7-4001-8f94-a2b4df29fbe8
public int getY(){ return this.y; }
dca477c8-85df-4402-8d38-936d003af8ec
public Index getTop(){ return new Index(this.x - 1, this.y); }
c1aa4068-5eb0-4dd8-a1b0-067117966d7b
public Index getBelow(){ return new Index(this.x + 1, this.y); }
f3a66f7e-26ea-438b-aaf8-caa2a6990a3d
public Index getLeft(){ return new Index(this.x, this.y - 1); }
8f35a67f-9bfd-41c6-b30c-8f6795e89767
public Index getRight(){ return new Index(this.x, this.y + 1); }
67f24c23-14ce-4f41-9889-56ae26acca69
public ArrayList<Index> getNear(){ ArrayList<Index> res = new ArrayList<Index>(); res.add(this.getTop()); res.add(this.getLeft()); res.add(this.getBelow()); res.add(this.getRight()); return res; }
2f08d127-1510-4fa4-adb4-074905df44f1
@Override public boolean equals(Object o){ if(o instanceof Index){ return ((Index)o).getX() == this.x && ((Index)o).getY() == this.y; } return false; }
36caa990-3f8b-4488-a794-67b6828c5d57
@Override public int hashCode(){ return this.x << 16 + this.y; }
b8cacc90-e954-44e5-849c-cb3c8176c561
public static void main(String[] args){ char[][] board = { "XOXOXO".toCharArray(), "OXOXOX".toCharArray(), "XOXOXO".toCharArray(), "OXOXOX".toCharArray(), }; SurroundedRegions s = new SurroundedRegions(); s.solve(board); for(int i = 0; i < board.l...
e62fe234-cd7c-424c-be20-6ac042bf43d0
public String multiply(String num1, String num2) { num1 = new StringBuffer(num1).reverse().toString(); num2 = new StringBuffer(num2).reverse().toString(); int[] d = new int[num1.length() + num2.length()]; for(int i = 0; i < num1.length(); i++){ int d1 = num1...
4d3218d2-99e4-4841-9940-37d9fd5c23c8
public static void main(String[] args){ MultiplyStrings s = new MultiplyStrings(); System.out.println(s.multiply("47721000541511454000", "54884321897654189789715879")); }
694c9aad-8f8f-49d0-ba64-456dd1f8750d
public ListNode sortList(ListNode head) { return mergeSort(head); }
eb093f67-8484-448f-b4ad-a8960a15537b
private ListNode mergeSort(ListNode node){ SortList.PrintListNode(node); if(node == null || node.next == null){ return node; } ListNode r1 = node, r2 = node.next; while(r2 != null && r2.next != null){ System.out.println("enter loop"); ...
3f4de79c-ff12-4362-90e2-6b61fd7a6757
private ListNode merge(ListNode n1, ListNode n2){ if(n2 == null || n1 == n2){ return n1; } ListNode dummy = new ListNode(0); ListNode runner = dummy; while(n1 != null && n2 != null){ if(n1.val < n2.val){ runner.next = n1; ...
616b9730-dd63-4199-a030-8ee2e0891ddf
public static void main(String[] args){ ListNode node1 = new ListNode(2); ListNode node2 = new ListNode(1); node1.next = node2; SortList sl = new SortList(); ListNode node = sl.sortList(node1); SortList.PrintListNode(node); }
3c101d88-1b18-4b08-b2cb-4eb8465b9ccb
public static void PrintListNode(ListNode node){ ListNode runner = node; while(runner != null){ System.out.print(runner.val + " -> "); runner = runner.next; } System.out.println(); }
f86acca7-8118-428c-a75b-3d8dd2eeb1d3
public ListNode reverseKGroup(ListNode head, int k) { ListNode ret = null; Queue<LinkedList<ListNode>> cache = new LinkedList<LinkedList<ListNode>>(); ListNode runner = head; while(runner != null){ LinkedList<ListNode> stack = new LinkedList<ListNod...
3b6de34b-f323-49b3-a2be-a6e77f14ef39
public static void main(String[] args){ ReverseNodesInKGroup s = new ReverseNodesInKGroup(); ListNode node = new ListNode(1); node.next = new ListNode(2); node.next.next = new ListNode(3); ListNode n = s.reverseKGroup(node, 2); System.out.println(n.val + " " + n.next.val ...
8bd70a13-6b44-4f96-8792-3b6f5538aebe
public ListNode mergeKLists(ArrayList<ListNode> lists) { // Create dummy head list node. ListNode head = new ListNode(0); // Instantiate priority queue as min heap. PriorityQueue<ListNode> queue = new PriorityQueue<ListNode>(lists.size() + 1, new Comparator<ListNode>(){ ...
56a3a793-cfb8-4a05-b964-d54c75766695
public int compare(ListNode node1, ListNode node2){ return node1.val - node2.val; }
138399d1-1024-471c-b833-49d292604d59
@Test public void testMergeKLists() { MergeKLists merge = new MergeKLists(); ArrayList<ListNode> lists = new ArrayList<ListNode>(); ListNode test1 = new ListNode(0); ListNode test2 = new ListNode(0); ListNode cur1 = test1, cur2 = test2; for(int i = 0; i < 10; i ++){ cur1.next = new ListNo...
0c1ce93c-143f-4844-a4d5-588dd546c9ef
public ArrayList<ArrayList<Integer>> combinationSum2(int[] num, int target) { ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); if(num.length < 1){ return result; } Arrays.sort(num); LinkedList<Integer> list = new LinkedList...
6acb6063-2868-4c7b-86c2-4701d023f7ab
private void found(ArrayList<ArrayList<Integer>> list, LinkedList<Integer> l, int last){ ArrayList<Integer> temp = new ArrayList<Integer>(l); temp.add(last); list.add(temp); }
bbcfcb6f-aec9-4069-a05d-604677218af4
private void makeUnique(ArrayList<ArrayList<Integer>> all) { // check if the adjacent index of all is the same for(int i =0;i<all.size()-1;i++){ ArrayList<Integer> curAl = all.get(i); for(int j = i+1;j<all.size();j++){ ArrayList<Integer> nextAl = all.get(j); ...
f7cdace5-c02f-4d5f-902b-778b0b68da8d
private boolean isSameList(ArrayList<Integer> list1, ArrayList<Integer> list2) { // check if the two list is the same if(list1.size() != list2.size()){ return false; } for(int i =0;i<list1.size();i++){ if(list1.get(i)!= list2.get(i)){ r...
1429f0e5-7e62-4e06-9cab-dd15bdf5b9d4
public static void main(String[] args){ int[] num = {4,1,1,4,4,4,4,2,3,5}; int target = 10; CombinationSumTwo cst = new CombinationSumTwo(); ArrayList<ArrayList<Integer>> result = cst.combinationSum2(num, target); for(int i = 0; i < result.size(); i++){ printList(r...
837ec7ff-43b9-4fc1-a040-ec701164384d
public static <E> void printList(List<E> list){ for(int i = 0; i < list.size(); i++){ System.out.print(list.get(i)); } System.out.println(); }
8bf06929-2a63-43d9-9d4a-a5fd835ce3c4
public static boolean loadAllFeatures() { String basepath = "/usr1/haijieg/kdd/features/"; // String basepath = "/Users/haijieg/workspace/kdd2012/features/"; descriptionFeature = new ArrayList<Set<Integer>>(3171830); titleFeature = new ArrayList<Set<Integer>>(4051441); queryFeature = new ArrayList<Set<Integer...
332ddb4d-48ed-4b9f-816b-d5014bbb422d
private static void loadUserFeature(String path, ArrayList<int[]> feature) throws FileNotFoundException { for (int i = 0; i < 23907635; i++) userFeature.add(new int[] { 0, 0 }); System.err.println("Loading feature from " + path); Scanner sc = new Scanner(new BufferedReader(new FileReader(path))); int line...
234104a7-2cd3-4b42-aa2e-8c6c0c7f58b5
private static void loadTokenFeature(String path, ArrayList<Set<Integer>> feature) throws FileNotFoundException { System.err.println("Loading feature from " + path); Scanner sc = new Scanner(new BufferedReader(new FileReader(path))); int line = 0; while (sc.hasNextLine()) { feature.add(parseFeature(sc.nex...
5912a6ac-0daa-43fa-8d1b-5a910ff5ca26
private static Set<Integer> parseFeature(String line) { StringTokenizer tokenizer = new StringTokenizer(line); Set<Integer> words = new HashSet<Integer>(3); String id = tokenizer.nextToken(); while (tokenizer.hasMoreElements()) { String token = tokenizer.nextToken("\\|").trim(); words.add(Integer.valueOf(...
850532e1-feb5-4b69-941d-c89abf0a0f78
public static void main(String[] args) { Features.loadAllFeatures(); }
e81c29e4-1498-41ae-8015-2cb36831c415
public static ArrayList<String> processLine(String line, boolean hasLabel) { StringTokenizer tokenizer = new StringTokenizer(line, "\t"); ArrayList<String> filteredTokens = new ArrayList<String>(); if (hasLabel) { filteredTokens.add(tokenizer.nextToken()); // push click filteredTokens.add(tokenizer.nextToke...
8cac5351-1311-4d34-8839-6484c933805c
public static void main(String args[]) throws FileNotFoundException, IOException { Features.loadAllFeatures(); String trainpath = "/usr1/haijieg/kdd/small/data/train.txt"; Scanner sc = new Scanner(new BufferedReader(new FileReader(trainpath))); FileWriter ftrainstream = new FileWriter( "/usr1/haijieg/kdd...
d054271d-d284-4963-a80b-391be920e0d1
public static String implode(Iterator iter, String delim) { StringBuilder builder = new StringBuilder(); builder.append(iter.next()); while (iter.hasNext()) { builder.append(delim); builder.append(iter.next()); } return builder.toString(); }
55f3bf35-6e48-4162-9e2b-d98b4072c92d
public static String implode(int[] arr, String delim) { StringBuilder builder = new StringBuilder(); builder.append(arr[0]); for (int i = 1; i < arr.length; i++) { builder.append(delim); builder.append(arr[i]); } return builder.toString(); }
f2f64f6c-4946-46c2-8855-ceb23187dced
public static int[] mapArrayStrToInt(String[] in) { int[] out = new int[in.length]; for (int i = 0; i < in.length; i++) { out[i] = Integer.valueOf(in[i]); } return out; }
02196c7f-6c43-4af0-abe8-39215930d727
public static double eval(String pathToSol, ArrayList<Double> ctr_prediction) { try { Scanner sc = new Scanner(new BufferedReader(new FileReader( pathToSol))); int size = ctr_prediction.size(); double wmse = 0.0; for (int i = 0; i < size; i++) { double ctr = Double.parseDouble(sc.nextLine()); ...
36407b8d-ac9b-4a36-b371-003ef7946194
public static double eval(String pathToSol, String pathToPrediction) { ArrayList<Double> ctr_prediction = new ArrayList<Double>(); try { Scanner sc = new Scanner(new BufferedReader(new FileReader(pathToPrediction))); while (sc.hasNextLine()) { try { ctr_prediction.add(Double.parseDouble(sc.nextLine()...
b6ef1b4c-b984-4985-954a-5e941e379ac4
public static double evalBaseLine(String pathToSol, double avg_ctr) { try { Scanner sc = new Scanner(new BufferedReader(new FileReader( pathToSol))); double rmse = 0.0; int count = 0; while(sc.hasNextLine()) { double ctr = Double.parseDouble(sc.nextLine()); rmse += Math.pow(ctr - avg_ctr, 2);...
40a6c967-88af-4770-9bb2-e66844a2c31d
public static double evalWithIncludingList(String pathToSol, ArrayList<Double> ctr_prediction, ArrayList<Boolean> includingList) { try { Scanner sc = new Scanner(new BufferedReader(new FileReader( pathToSol))); int size = ctr_prediction.size(); double wmse = 0.0; int total = 0; for (int i = 0; i <...
0d7d5591-5ac4-42df-b329-8e5e9a55579a
public static int hashToRange(String s, int upper) { int hashval = s.hashCode() % upper; if (hashval < 0) hashval = upper + hashval; return hashval; }
66194163-bd21-4d1d-99f6-0f21c73fd4f2
public static int hashToSign(String s) { if (s.hashCode() % 2 == 0) return -1; else return 1; }
1b8f6f1b-f251-48a2-89e1-72ba0b1f3b02
public DataSet(String path, boolean isTraining, int size) throws FileNotFoundException { this.path = path; this.hasLabel = isTraining; this.size = size; sc = new Scanner(new BufferedReader(new FileReader(path))); }
2a0d2952-3911-4933-93e1-1a493db49f38
public boolean hasNext() { return (counter < size) && sc.hasNextLine(); }
a35706eb-53ea-4183-981d-758788399e88
public DataInstance nextInstance() { counter++; return new DataInstance(sc.nextLine(), hasLabel); }
fed6fd76-4df7-4133-bc5e-fabe397f4d53
public HashedDataInstance nextHashedInstance(int featuredim, boolean personal) { counter++; return new HashedDataInstance(sc.nextLine(), hasLabel, featuredim, personal); }
85128bc8-c21f-4e1e-9417-236e5ab094a3
public void reset() { counter = 0; sc.close(); try { sc = new Scanner(new BufferedReader(new FileReader(path))); } catch (FileNotFoundException e) { e.printStackTrace(); } }
34f82d7e-8aad-4a4c-8a85-8fada233d768
public DataInstance(String line, boolean hasLabel) { String[] fields = line.split("\\|"); int offset = 0; if (hasLabel) { clicked = Integer.valueOf(fields[0]); offset = 1; } else { clicked = -1; } depth = Integer.valueOf(fields[offset + 0]); position = Integer.valueOf(fields[offset + 1]); useri...
8f5ba92b-3a0a-4817-8252-adeb0cc9e7e1
@Override public String toString() { StringBuilder builder = new StringBuilder(); if (clicked >= 0) { builder.append(clicked + "|"); } builder.append(depth + "|" + position + "|"); builder.append(userid + "|" + gender + "|" + age + "|"); builder.append(StringUtil.implode(tokens, ",")); return builder....
556262b0-14eb-471a-95b2-9e7685601398
public HashedDataInstance(String line, boolean hasLabel, int dim, boolean personal) { String[] fields = line.split("\\|"); int offset = 0; if (hasLabel) { clicked = Integer.valueOf(fields[0]); offset = 1; } else { clicked = -1; } depth = Integer.valueOf(fields[offset + 0]); position = Integ...
4a324e59-3ace-48e0-9783-659add160abb
private void updateFeature(String key, int val) { }
f178b223-bb97-4f5e-a8f7-4e78ba1ec112
public Weights() { w0 = wAge = wGender = wDepth = wPosition = 0.0; wTokens = new HashMap<Integer, Double>(); accessTime = new HashMap<Integer, Integer>(); }
5216b28b-10fb-45b8-a710-6d7f97d0eb27
@Override public String toString() { DecimalFormat myFormatter = new DecimalFormat("###.##"); StringBuilder builder = new StringBuilder(); builder.append("Intercept: " + myFormatter.format(w0) + "\n"); builder.append("Depth: " + myFormatter.format(wDepth) + "\n"); builder.append("Position: " + myFormat...
0c9c781e-c8ac-4b3f-8590-bb0d283afa91
public double l2norm() { double l2 = w0 * w0 + wAge * wAge + wGender * wGender + wDepth*wDepth + wPosition*wPosition; for (double w : wTokens.values()) l2 += w * w; return Math.sqrt(l2); }
6010417b-a4e6-4130-b447-86af36e316d9
public int l0norm() { return 4 + wTokens.size(); }
b4a2c6b5-38dc-4e1b-8afa-023851b7f2bf
private double computeWeightFeatureProduct(Weights weights, DataInstance instance) { // Fill in your code here // w0 | wAge | wGender | wDepth | wPosition | wTokens; double tokenSum = 0; int[] instTokens = instance.tokens; Map<Integer, Double> allTokens = weights.wTokens; for (i...
4a34db39-f2c3-42e1-bb76-2009eb2fe83c
private void performDelayedRegularization(int[] tokens, Weights weights, int now, double step, double lambda) { // Fill in your code here. }
233996c9-99de-4fc1-a87e-e37942f11d53
public Weights train(DataSet dataset, double lambda, double step, ArrayList<Double> AvgLoss) { int count = 0; Weights myWeights = new Weights(); double loss = 0; double avLoss; while (dataset.hasNext()) { count++; DataInstance instance = dataset.nextInstance(); //performDelayedRegulari...
3dabbb7b-5162-4ca3-8053-ad3f1cc462ec
public ArrayList<Double> predict(Weights weights, DataSet dataset) { ArrayList<Double> y_hat = new ArrayList<Double>(); while (dataset.hasNext()) { DataInstance instance = dataset.nextInstance(); Double predicted = 00.00; y_hat.add(predicted); } return y_hat; }
3d1a32c0-bdd4-4e31-9d42-7fb49ea69ea2
public static void main(String args[]) throws IOException { String seperator = System.getProperty("line.separator"); int trainSize = 2335859; int testSize = 1016552; DataSet training = new DataSet( "/Users/cbboipdx/data/clickprediction/data/train.txt", true, trainSize); Data...
3b157c21-8bc0-495b-bd2f-e23dfb0dc5c9
public Set<Integer> uniqTokens(DataSet dataset) { int count = 0; // new calls the contructor for thge class HashSet Set<Integer> ids = new HashSet<Integer>(); while(dataset.hasNext()) { DataInstance instance = dataset.nextInstance(); int[] tokens = instance.tokens;...
0b6d62cd-a9b3-4075-ada5-579b3d99cc66
public Map<Integer, Set<Integer>> uniqUsersPerAgeGroup(DataSet dataset) { Map<Integer, Set<Integer>> usersAge = new HashMap<Integer, Set<Integer>>(); int count = 0; while(dataset.hasNext()) { DataInstance instance = dataset.nextInstance(); int thisAge = instance.age; int thisId =...
461dd3cc-25b1-477e-aa90-d3417c9c87a0
public double averageCtr(DataSet dataset) { int clickSum = 0; int numExamples = 0; while(dataset.hasNext()) { DataInstance instance = dataset.nextInstance(); clickSum += instance.clicked; numExamples++; if (numExamples % 100000 == 0) { System.err.println("Load...
147b4a86-e3fe-432c-b995-c7d978c01b89
public static void main(String args[]) throws Exception { // Fill in your code here }
c949860b-497c-4480-a313-aa7de71d92d1
public void scanAndPrint(DataSet dataset) { int count = 0; //int clickSum = 0; System.err.println("Loading data from " + dataset.path + " ... "); while (dataset.hasNext()) { DataInstance instance = dataset.nextInstance(); /** * Here we printout the instance. But your code for processing each * ins...