I'm new Java and am using jGraphT to create a SimpleDirectedWeightedGraph. I'm getting this error when trying to set weights on my edges after creating and adding them to the graph:
Exception in thread "main" java.lang.ClassCastException: ObservationsDAG$ObservationsDAGEdge cannot be cast to org.jgrapht.graph.DefaultWeightedEdge
at org.jgrapht.graph.AbstractBaseGraph.setEdgeWeight(Unknown Source)
I am assuming I need to do something in my ObservationsDAGEdge class here, but from looking at the JGraphT docs, I am stuck as to what that is. Does my edge class need weight instance variable and do I need to provide getEdgeWeight() and setEdgeWeight()?
So, I figured this out. I first tried extending DefaultDirectedEdge, but then getEdgeTarget() stopped working - probably because I need to implement start/end vertices.
After reading the code, I tried subclassing SimpleDirectedWeightedGraph and overrode setEdgeWeight and getEdgeWeight and gave my edge class a weight instance variable.
That finally worked as sexpected.
Related
AIS_DimensionOwner class is deprecated and PrsDim_DimensionOwner is the new one. Iam migrating old code from 6.5.0 to 7.6.0.
before I had:
Handle(AIS_DimensionOwner ) own1 = new AIS_DimensionOwner (this ,7);
own1->SetShape(mySShape);
and now:
Handle(PrsDim_DimensionOwner) own1 = new PrsDim_DimensionOwner(this, PrsDim_DimensionSelectionMode::PrsDim_DimensionSelectionMode_All ,7);
but the second line above, I didn't find an equivalent
I would appreciate any suggestion
It is important to mention from which OCCT version you are porting legacy code to which new one.
According to git log, AIS_DimensionOwner::SetShape() has been removed in OCCT 6.7.0 in '2013 by 0024133: Development of improvement of dimensions implementation; new length, radius,diameter and angle dimensions.
I cannot find direct description, but it looks Shape property has been removed as irrelevant and unused. So that the main thing to pass is appropriate enumeration value to class constructor and second line could be just removed, if no further application code reads Shape back. Otherwise, you may make a subclass and add this property on your own.
I'm having challenges with some IGES/STEP models where my code is not able to classify faces bases on the underlying classification of edges i.e whether an edge is a Straight line(non-rational Bspline curve) or arc(rational Bspline curve). I have been using the code below (which works for some models):
edgex.setIsRational(BRepAdaptor_Curve(edge).IsRational());
,where the edge is a TopoDS_Edge and edgex is a custom Edge object.
I also tried the following code but it crashes the program on the second line:
BRepAdaptor_Curve curve = BRepAdaptor_Curve(edge);
Handle_Geom_BSplineCurve spline = curve.BSpline();
edgex.setIsRational(spline.IsRational())
May you please help with a better method or fix for my solutions. Thank you in advance.
You can use the BrepAdaptor::GetType() method to determine the type of curve. The crash in the second line occurs, apparently, that the edge is not a BSpline curve, and the BrepAdaptor::BSpline() method creates a copy, and there is nothing to make it from.
I'm trying to implement GradCam (https://arxiv.org/pdf/1610.02391.pdf) in tfjs, based on the following Keras Tutorial (http://www.hackevolve.com/where-cnn-is-looking-grad-cam/) and a simple image classification demo from tfjs, similar to (https://github.com/tensorflow/tfjs-examples/blob/master/webcam-transfer-learning/index.js) with a simple dense, fully-connected layer at the end.
However, I'm not able to retrieve the gradients needed for the gradcam computation. I tried different ways to retrieve gradients for the last sequential layer, but did not succeed, as types of tf.LayerVariable from the respective layer is not convertible to the respective type of tf.grads or tf.layerGrads.
Did anybody already succeeded to get the gradients from sequential layer to a tf.function like object?
I'm not aware of the ins and outs of the implementation, but I think something along the lines of this: http://jlin.xyz/advis/ is what you're looking for?
Source code is available here: https://github.com/jaxball/advis.js (not mine!)
This official example in the tfjs-examples repo should be close to, if not exactly, what you want:
https://github.com/tensorflow/tfjs-examples/blob/master/visualize-convnet/cam.js#L49
I have a List of Strings that I want to set as a parameter in a preparedstatement. This question and answer here, makes it look easy:
How to use an arraylist as a prepared statement parameter
Well, not really easy. There is still the conversion of a List, to an SQL-Array, which I found easiest to do by creating a String[] in between.
Below is my code:
PreparedStatement s = con.prepareStatement("SELECT * FROM Table WHERE Country IN ? ");
String[] countryArray = new String[countryListObject.size()];
countryArray = countryListObject.toArray(countryArray);
Array cArray = con.createArrayOf("VARCHAR", countryArray); //<--- Throws the exception
s.setArray(1, cArray);
This answer Seems to adress a similar problem, but I can't really understand how this helped solve anything. The answer is ambigous at best, stating only that:
Basically what you are wanting to do is not directly possible using a
PreparedStatement.
I've come to learn from the API Documentation that this exception is thrown if the JDBC driver does not support this method. I'm running a com.microsoft.sqlserver sqljdbc4 version 3.0. I am trying to see which versions do and don't support setArray, but I can't find the information. It is probably right in front of me, but I would really appreciate a little help on this.
How can I figure out if my JDBC's do support setArray()?
I've been getting errors when trying to do many-to-many relations in Slick. This test shows how to do many-to-many relations in Slick. I followed it but then go this error:
Select(TableNode, "id") found. This is typically caused by an attempt to use a "raw" table object directly in a query without introducing it through a generator
I then found out that this is caused by declaring your tables at a static location (an object) and then trying to import it (it works fine if the object is in the same block). http://slick.typesafe.com/doc/1.0.0/lifted-embedding.html#tables
Ok, so val T = new Table inside of an object is the answer. But now I'm getting this error:
recursive method bs needs result type
It doesn't need a result type if it is an object and not a val. I've heard of using a class but I can't find any examples on how to do this.
How do you declare many-to-many models and import them from somewhere else?
EDIT:
Here's a gist showing what I mean: https://gist.github.com/pjrt/5332311
If you run the first test, it will pass, no issue.
If you run the second test, the following error is thrown:
scala.slick.SlickException: Select(TableNode, "id") found. This is typically caused by an attempt to use a "raw" table object directly in a query without introducing it through a generator.
If you run the third test (using vals inside of objects instead of objects directly), you get this error:
recursive method bs needs result type
[error] val A = new Table[(Int, String)]("a") {
recursive value AToB needs type
[error] def as = AToB.filter(_.bId === id).flatMap(_.aFK)
I know why the errors are happening, but I want to know how people got around them. One way is to put the objects inside of a class and instantiating a class every time you want to use Slick (but this seems...weird). Another is to never use Slick-related stuff outside of the package (or at least many-to-many stuff) but that also seems bad.
My question, still is, how do you guys get around this? Is there a proper way?
The error message you showed makes me think that you defined your tables but tried to access them directly instead of using a for comprehension.
The test file you were referring has an example right at the bottom, after defining the many-to-many tables that goes like
val q1 = for {
a <- A if a.id >= 2
b <- a.bs
} yield (a.s, b.s)
q1.foreach(x => println(" "+x))
assertEquals(Set(("b","y"), ("b","z")), q1.list.toSet)
What you see is that object table A is used as a comprehension generator (i.e. a <- A)
Does your code access the tables in some other way?