/** * Runs a test that compares the tree calculation with the real values of a given user This * recommendation type allows to calculate an RMSE value that indicates the quality of the * recommendations produced by the clusterer */ public Map<Integer, IAttribute> runTestRecommendation(INode testNode) { // Find position of the similar node in the tree INode position = leavesMapU.get((int) testNode.getDatasetId()); if (position == null) { return null; } else { // Collect ratings of all content given by the input node Map<Integer, IAttribute> contentRatings = collectRatings(position, testNode, null); return contentRatings; } }
/** * Collect ratings of all content given by the input node * * @param position this is the starting point for collecting * @param inputNodeID this node defines the content that needs to be collected */ public Map<Integer, IAttribute> collectRatings( INode position, INode testNode, Map<Integer, IAttribute> contentRatings) { // Create Map for content of test user with empty values if not existing if (contentRatings == null) { contentRatings = new HashMap<Integer, IAttribute>(); // DatasetID, AttributeData Set<INode> testContentKeys = testNode.getAttributeKeys(); for (INode testContentKey : testContentKeys) { contentRatings.put((int) testContentKey.getDatasetId(), null); } } // Look for content nodes on the list and add it to collected ratings map Set<INode> posContentKeys = position.getAttributeKeys(); Map<Integer, IAttribute> posContentMap = new HashMap<Integer, IAttribute>(); for (INode posContentKey : posContentKeys) { // Find Dataset ID of Content Node -> FIXME: very inefficient int contentDatasetID = 0; for (Iterator<Entry<Integer, INode>> iter = leavesMapC.entrySet().iterator(); iter.hasNext(); ) { Map.Entry<Integer, INode> e = (Map.Entry<Integer, INode>) iter.next(); if (posContentKey.getId() == e.getValue().getId()) { contentDatasetID = e.getKey(); } } posContentMap.put(contentDatasetID, position.getAttributeValue(posContentKey)); } for (Entry<Integer, IAttribute> contentRating : contentRatings.entrySet()) { int datasetID = contentRating.getKey(); IAttribute rating = contentRating.getValue(); // Check if value still needs to be found if (rating == null) { try { IAttribute contentAttributes = posContentMap.get(datasetID); contentRatings.put(datasetID, posContentMap.get(datasetID)); } catch (Exception e) { System.out.println(e); } } } // Check if all movies were found if (contentRatings.containsValue(null) != true) { return contentRatings; } else { // Go one level up if possible if (position.getParent() != null) { contentRatings = collectRatings(position.getParent(), testNode, contentRatings); if (contentRatings != null) { return contentRatings; } } else { return contentRatings; } } return null; }